std::multiset intersection compilation error - c++

I'm trying to find the intersection of 2 multisets of objects using std::set_intersection function.
#include <algorithm>
#include <set>
struct Interval
{
double bottom;
double top;
};
struct cmp_interval
{
bool operator()(Interval a, Interval b) const
{
return a.bottom < b.bottom;
}
}
int main()
{
std::multiset<Interval, cmp_interval> I1;
Interval i;
i.bottom = 20;
i.top = 30;
I1.insert(i);
std::multiset<Interval, cmp_interval> I2;
I2.insert(i);
std::multiset<Interval, cmp_interval> I3;
std::set_intersection(I1.begin(), I1.end(), I2.begin(), I2.end(), std::inserter(I3, I3.begin()));
return 0;
}
When I try to compile it, i get a page of verbose errors that I'm unable to properly understand. I'm still a novice in c++ although i do understand some fundamental concepts. Below is the error log generated,
Starting build...
/usr/bin/g++ -g /home/jamal/Documents/daa_assignment_1/measure.cpp -o /home/jamal/Documents/daa_assignment_1/measure
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /home/jamal/Documents/daa_assignment_1/measure.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = std::_Rb_tree_const_iterator<Interval>; _Iterator2 = std::_Rb_tree_const_iterator<Interval>]’:
/usr/include/c++/9/bits/stl_algo.h:5252:12: required from ‘_OutputIterator std::__set_intersection(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = std::_Rb_tree_const_iterator<Interval>; _InputIterator2 = std::_Rb_tree_const_iterator<Interval>; _OutputIterator = std::insert_iterator<std::multiset<Interval, cmp_interval> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/9/bits/stl_algo.h:5307:48: required from ‘_OIter std::set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter) [with _IIter1 = std::_Rb_tree_const_iterator<Interval>; _IIter2 = std::_Rb_tree_const_iterator<Interval>; _OIter = std::insert_iterator<std::multiset<Interval, cmp_interval> >]’
/home/jamal/Documents/daa_assignment_1/measure.cpp:338:100: required from here
/usr/include/c++/9/bits/predefined_ops.h:43:23: error: no match for ‘operator<’ (operand types are ‘const Interval’ and ‘const Interval’)
43 | { return *__it1 < *__it2; }
| ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /home/jamal/Documents/daa_assignment_1/measure.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’
915 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
| ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /home/jamal/Documents/daa_assignment_1/measure.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:43:23: note: ‘const Interval’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
43 | { return *__it1 < *__it2; }
| ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /home/jamal/Documents/daa_assignment_1/measure.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: candidate: ‘template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)’
922 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
| ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /home/jamal/Documents/daa_assignment_1/measure.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:43:23: note: ‘const Interval’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
43 | { return *__it1 < *__it2; }
| ~~~~~~~^~~~~~~~
Build finished with error(s).
The terminal process failed to launch (exit code: -1).
Any help would be appreciated. Thank you.
Update:
From the error log, I see that there's another optional argument that needs to be passed for std::set_intersection for custom comparator.
/usr/include/c++/9/bits/stl_algo.h:5252:12: required from ‘_OutputIterator std::__set_intersection(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = std::_Rb_tree_const_iterator<Interval>; _InputIterator2 = std::_Rb_tree_const_iterator<Interval>; _OutputIterator = std::insert_iterator<std::multiset<Interval, cmp_interval> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
The _Compare parameter looks to be by default
__gnu_cxx::__ops::_Iter_less_iter. I want to use comparator class that i have made(cmp_interval) there but it doesn't accept classes.

std::multiset<Interval, cmp_interval> I3;
Here, you specify the type of the comparator, as a type template argument. The actual comparator object is created inside the constructor of the multiset. Now you want to pass a similar object to the std::set_intersection function. Use:
std::set_intersection(I1.begin(), I1.end(),
I2.begin(), I2.end(),
std::inserter(I3, I3.begin()),
cmp_interval());
The empty parenthesis in cmp_interval() mean: an unnamed default-constructed object. You could also use cmp_interval{}, since C++11.

Related

Using Lambda on binary_search and replace_if

I have been trying to get this to where binary_search would answer the if statement as true or false. I have not had problems with that in the past, however I am having issues getting it to search the tempStr in the struct I have made up. What I am trying to achieve with binary_search is for it to say whether the product exists or not, and make the decision whether to even bother doing a for loop or not to actually go out and get the name of the product. I get errors when I execute, and I do not understand why.
The second issue I have incurred is that I want to replace the price that is already in the vector with one that the user inputs, however this incurs similar errors to that of the binary_search. This is something I had made in my naïve attempt to make this happen, any and all help will be greatly appreciated.
Will clarify if I am asked to do so.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct grocery{
string name;
string expdate;
string price;
};
int main(){
grocery tempProd;
string tempStr;
vector<grocery> produce;
cout << "What grocery product are you looking for?";
getline(cin, tempStr);
if(binary_search(produce.begin(), produce.end(), [&] (const grocery &p) {return p.name == tempStr;})){
cout << "Product has been found!" << endl;
for(int i= 0; i<produce.size(); i++){
if(produce[i].name == tempStr){
string tempStr2;
cout << "What is going to be the new price of the product?";
getline(cin, tempStr2);
replace_if(produce.begin(), produce.end(), produce[i].price,
[&] (const grocery &p) {return p.price == tempStr2;});
}
}
}
else{
cout << "Product does not exist." << endl;
}
}
I have mainly messed about with lambda for this, however it has not brought me much, if any success. Pointers also seemed like they would be the answer to me, but that did not do me much good either, and I just seem to find myself back here, at this location.
Here is how the struct is set up, and how the vector is set up since I know both of those are important.
Errors
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h: In instantiation of 'bool std::binary_search(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<body*, std::vector<body> >; _Tp = main()::<lambda(const body&)>]':
teste.cpp:45:117: required from here
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: error: no match for 'operator<' (operand types are 'const main()::<lambda(const body&)>' and 'body')
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:64,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_pair.h:454:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
454 | operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_pair.h:454:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::pair<_T1, _T2>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:331:5: note: candidate: 'template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
331 | operator<(const reverse_iterator<_Iterator>& __x,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:331:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::reverse_iterator<_Iterator>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:369:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
369 | operator<(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:369:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::reverse_iterator<_Iterator>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:1163:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
1163 | operator<(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:1163:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::move_iterator<_IteratorL>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:1169:5: note: candidate: 'template<class _Iterator> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
1169 | operator<(const move_iterator<_Iterator>& __x,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:1169:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::move_iterator<_IteratorL>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\string:55,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\ios_base.h:41,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:42,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6226:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
6226 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6226:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\string:55,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\ios_base.h:41,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:42,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6239:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)'
6239 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6239:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\string:55,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\ios_base.h:41,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:42,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6251:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
6251 | operator<(const _CharT* __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:6251:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: mismatched types 'const _CharT*' and 'main()::<lambda(const body&)>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\ios_base.h:46,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:42,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\system_error:208:3: note: candidate: 'bool std::operator<(const std::error_code&, const std::error_code&)'
208 | operator<(const error_code& __lhs, const error_code& __rhs) noexcept
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\system_error:208:31: note: no known conversion for argument 1 from 'const main()::<lambda(const body&)>' to 'const std::error_code&'
208 | operator<(const error_code& __lhs, const error_code& __rhs) noexcept
| ~~~~~~~~~~~~~~~~~~^~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\system_error:282:3: note: candidate: 'bool std::operator<(const std::error_condition&, const std::error_condition&)'
282 | operator<(const error_condition& __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\system_error:282:36: note: no known conversion for argument 1 from 'const main()::<lambda(const body&)>' to 'const std::error_condition&'
282 | operator<(const error_condition& __lhs,
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\vector:67,
from teste.cpp:3:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_vector.h:1905:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)' 1905 | operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_vector.h:1905:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\algorithm:62,
from teste.cpp:5:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2259:39: note: 'const main()::<lambda(const body&)>' is not derived from 'const std::vector<_Tp, _Alloc>'
2259 | return __i != __last && !(__val < *__i);
| ~~~~~~~^~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h: In instantiation of 'void std::replace_if(_FIter, _FIter, _Predicate, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<body*, std::vector<body> >; _Predicate = std::__cxx11::basic_string<char>; _Tp = main()::<lambda(const body&)>]':
teste.cpp:53:82: required from here
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:4401:12: error: no match for call to '(std::__cxx11::basic_string<char>) (body&)'
4401 | if (__pred(*__first))
| ~~~~~~^~~~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:4402:13: error: no match for 'operator=' (operand types are 'body' and 'const main()::<lambda(const body&)>')
4402 | *__first = __new_value;
| ~~~~~~~~~^~~~~~~~~~~~~
teste.cpp:9:8: note: candidate: 'body& body::operator=(const body&)'
9 | struct body{
| ^~~~
teste.cpp:9:8: note: no known conversion for argument 1 from 'const main()::<lambda(const body&)>' to 'const body&'
teste.cpp:9:8: note: candidate: 'body& body::operator=(body&&)'
teste.cpp:9:8: note: no known conversion for argument 1 from 'const main()::<lambda(const body&)>' to 'body&&'
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:71,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<body*, std::vector<body> >; _Value = const main()::<lambda(const body&)>]':
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:979:14: required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator =
__gnu_cxx::__normal_iterator<body*, std::vector<body> >; _Tp = main()::<lambda(const body&)>; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algo.h:2257:22: required from 'bool std::binary_search(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<body*, std::vector<body> >; _Tp = main()::<lambda(const body&)>]'
teste.cpp:45:117: required from here
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\predefined_ops.h:65:22: error: no match for 'operator<' (operand types are 'body' and 'const main()::<lambda(const body&)>')
65 | { return *__it < __val; }
| ~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:915:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
915 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:915:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:71,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\predefined_ops.h:65:22: note: 'body' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
65 | { return *__it < __val; }
| ~~~~~~^~~~~~~
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:67,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:922:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
922 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
| ^~~~~~~~
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_iterator.h:922:5: note: template argument deduction/substitution failed:
In file included from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_algobase.h:71,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\char_traits.h:39,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:40,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from teste.cpp:1:
c:\cpp\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\predefined_ops.h:65:22: note: 'body' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
65 | { return *__it < __val; }
edit: yes I know the example doesn't have a grocery yet, but having a grocery or not has NOT caused a problem, as I am working with information from a text file, this is literally the bare minimum that causes the issues I am getting.
Even if the compiler error relating to binary_search is fixed (which is a bit tricky, since binary_search searches for a grocery and not a string), it won't help you. That is because binary_search requires the vector to be sorted to work correctly and it isn't, here.
Therefore, replace it with std::find_if, which does not have this requirement:
auto it = std::find_if (produce.begin(), produce.end(), [&] (const grocery &g) {return g.name == tempStr;});
Doing that means that you don't then need to search the vector again for the matching item since you already have an iterator pointing right at it. Instead, you can just do:
if (it != produce.end()){
cout << "Product has been found!" << endl;
cout << "What is going to be the new price of the product?";
string tempStr2;
getline(cin, tempStr2);
it->price = tempStr2;
}
else{
cout << "Product does not exist." << endl;
}
All in all, a better solution.
Live demo

Creating std::map with a structure as its key and value [duplicate]

This question already has answers here:
Error using custom operator< with std::less
(2 answers)
Closed 4 years ago.
I want to define a static map inside a class, which will have a structure as both it's key and value. I've read that a '<' operator is needed to be defined, therefore I've included that definition inside the struct itself(I've randomly defined it as I don't need any comparison anywhere in my program).
The below sample code doesn't compile.The compiler produces a lot of warnings and errors which I don't understand right now. (Please ignore the uninitialized values in the main function):
#include<string>
#include<iostream>
#include<map>
using namespace std;
struct RJNodeAddress
{
string m_ip;
string m_port;
bool operator<(const RJNodeAddress &l)
{
int l_size=l.m_ip.size();
int r_size=l.m_port.size();
return (l_size < r_size);
}
};
struct RJNodeDetails
{
string m_NodeType;
int m_appId;
};
class RJWebsocket
{
public:
static map<RJNodeAddress,RJNodeDetails> m_Nodes;
};
int main()
{
RJNodeAddress l_node;
RJNodeDetails l_nodeDetails = RJWebsocket::m_Nodes[l_node];
}
Compiler output
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h: In instantiation of âconstexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = RJNodeAddress]â:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:491:32: required from âstd::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = RJNodeAddress; _Tp = RJNodeDetails; _Compare = std::less<RJNodeAddress>; _Alloc = std::allocator<std::pair<const RJNodeAddress, RJNodeDetails> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = RJNodeDetails; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = RJNodeAddress]â
test.cpp:34:59: required from here
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: error: no match for âoperator<â (operand types are âconst RJNodeAddressâ and âconst RJNodeAddressâ)
{ return __x < __y; }
~~~~^~~~~
test.cpp:10:14: note: candidate: bool RJNodeAddress::operator<(const RJNodeAddress&) <near match>
bool operator<(const RJNodeAddress &l)
^~~~~~~~
test.cpp:10:14: note: passing âconst RJNodeAddress*â as âthisâ argument discards qualifiers
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:64:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::pair<_T1, _T2>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
operator<(const move_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::basic_string_view<_CharT, _Traits>)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >, std::basic_string_view<_CharT, _Traits>)
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: mismatched types âconst _CharT*â and âRJNodeAddressâ
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/ios_base.h:46:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ios:42,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ostream:38,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/iostream:39,
from test.cpp:2:
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: candidate: bool std::operator<(const std::error_code&, const std::error_code&)
operator<(const error_code& __lhs, const error_code& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_code&â
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: candidate: bool std::operator<(const std::error_condition&, const std::error_condition&)
operator<(const error_condition& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_condition&â
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const std::optional<_Up>&)
operator<(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: candidate: template<class _Tp> constexpr bool std::operator<(const std::optional<_Tp>&, std::nullopt_t)
operator<(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: candidate: template<class _Tp> constexpr bool std::operator<(std::nullopt_t, const std::optional<_Tp>&)
operator<(nullopt_t, const optional<_Tp>& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const _Up&)
operator<(const optional<_Tp>& __lhs, const _Up& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Up>() < declval<_Tp>()))> std::operator<(const _Up&, const std::optional<_Tp>&)
operator<(const _Up& __lhs, const optional<_Tp>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: candidate: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::array<_Tp, _Nm>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: candidate: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Tps ...>&, const std::tuple<_Elements ...>&)
operator<(const tuple<_TElements...>& __t,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::tuple<_Tps ...>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:61:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::map<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:62:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::multimap<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
As keys in std::map are const your operator< method must be const as well:
bool operator<(const RJNodeAddress &l) const
// ^ here
it should be const anyway as it does not modify the object but in this case missing it leads to compilation errors.

Unique_ptr c++ usage

Sincerelly i m not so expert with c++ RAII features. I never used before. Anyway i m begining to study about it (i m in "kernel panic"). Compiling a module i have the following error :
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’:
/usr/include/c++/6/bits/unique_ptr.h:539:9: required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’
java/rocksjni/compaction_filter_factory_jnicallback.cc:33:58: required from here
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
from /usr/include/c++/6/bits/stl_algobase.h:64,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)
swap(_Tp& __a, _Tp& __b)
^~~~
/usr/include/c++/6/bits/move.h:179:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’)
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
from /usr/include/c++/6/bits/stl_algobase.h:64,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
^~~~
/usr/include/c++/6/bits/move.h:202:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
^~~~
/usr/include/c++/6/bits/stl_pair.h:471:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/stdexcept:39,
from /usr/include/c++/6/array:39,
from /usr/include/c++/6/tuple:39,
from /usr/include/c++/6/functional:55,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~
/usr/include/c++/6/bits/basic_string.h:5287:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/tuple:39:0,
from /usr/include/c++/6/functional:55,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
^~~~
/usr/include/c++/6/array:275:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/functional:55:0,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&)
swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
^~~~
/usr/include/c++/6/tuple:1546:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:79:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)
swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
^~~~
/usr/include/c++/6/functional:2238:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’:
/usr/include/c++/6/bits/unique_ptr.h:539:9: required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’
java/rocksjni/comparatorjnicallback.cc:34:21: required from here
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
from /usr/include/c++/6/bits/stl_algobase.h:64,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)
swap(_Tp& __a, _Tp& __b)
^~~~
/usr/include/c++/6/bits/move.h:179:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’)
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
from /usr/include/c++/6/bits/stl_algobase.h:64,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
^~~~
/usr/include/c++/6/bits/move.h:202:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
from /usr/include/c++/6/memory:62,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
^~~~
/usr/include/c++/6/bits/stl_pair.h:471:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/stdexcept:39,
from /usr/include/c++/6/array:39,
from /usr/include/c++/6/tuple:39,
from /usr/include/c++/6/functional:55,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~
/usr/include/c++/6/bits/basic_string.h:5287:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/tuple:39:0,
from /usr/include/c++/6/functional:55,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
^~~~
/usr/include/c++/6/array:275:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/functional:55:0,
from /usr/include/c++/6/memory:79,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&)
swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
^~~~
/usr/include/c++/6/tuple:1546:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:79:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)
swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
^~~~
/usr/include/c++/6/functional:2238:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
from ./java/./rocksjni/comparatorjnicallback.h:13,
from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
swap(std::get<0>(_M_t), __p);
I m not sure to understand this stack trace but it seams there is a mismatch in the unique_ptr . Maybe const char* and char*.
the class where there is the bug is :
CompactionFilterFactoryJniCallback::CompactionFilterFactoryJniCallback(
JNIEnv* env, jobject jcompaction_filter_factory)
: JniCallback(env, jcompaction_filter_factory) {
// Note: The name of a CompactionFilterFactory will not change during
// it's lifetime, so we cache it in a global var
jmethodID jname_method_id =
AbstractCompactionFilterFactoryJni::getNameMethodId(env);
if(jname_method_id == nullptr) {
// exception thrown: NoSuchMethodException or OutOfMemoryError
return;
}
jstring jname =
(jstring)env->CallObjectMethod(m_jcallback_obj, jname_method_id);
if(env->ExceptionCheck()) {
// exception thrown
return;
}
jboolean has_exception = JNI_FALSE;
// line 33
m_name = JniUtil::copyString(env, jname, &has_exception); // also releases jname
if (has_exception == JNI_TRUE) {
// exception thrown
return;
}
m_jcreate_compaction_filter_methodid =
AbstractCompactionFilterFactoryJni::getCreateCompactionFilterMethodId(env);
if(m_jcreate_compaction_filter_methodid == nullptr) {
// exception thrown: NoSuchMethodException or OutOfMemoryError
return;
}
}
const char* CompactionFilterFactoryJniCallback::Name() const {
return m_name.get();
}
std::unique_ptr<CompactionFilter> CompactionFilterFactoryJniCallback::CreateCompactionFilter(
const CompactionFilter::Context& context) {
jboolean attached_thread = JNI_FALSE;
JNIEnv* env = getJniEnv(&attached_thread);
assert(env != nullptr);
jlong addr_compaction_filter = env->CallLongMethod(m_jcallback_obj,
m_jcreate_compaction_filter_methodid,
static_cast<jboolean>(context.is_full_compaction),
static_cast<jboolean>(context.is_manual_compaction));
if(env->ExceptionCheck()) {
// exception thrown from CallLongMethod
env->ExceptionDescribe(); // print out exception to stderr
releaseJniEnv(attached_thread);
return nullptr;
}
auto* const cff = reinterpret_cast<CompactionFilter*>(addr_compaction_filter);
releaseJniEnv(attached_thread);
return std::unique_ptr<CompactionFilter>(cff);
}
It is not clear how to read this stack trace for identifying the problem. I would appreciate to receive a little suggestion for understand how fix the problem and read the stack trace.
The error says that you have a std::unique_ptr<char const[]> object on which you try to call function reset passing char* as an argument.
Well, that argument needs to be char const* for that to compile, which you can achieve with a const_cast, e.g.:
std::unique_ptr<char const[]> p;
char* q = new char[1]{};
p.reset(const_cast<char const*>(q));
Looks like JniUtil::copyString returns std::unique_ptr<char[]> and you assign it to std::unique_ptr<char const[]> which causes the error.
One fix is to change the type of m_name to be std::unique_ptr<char[]>.
Another is to manually add constness (adding constness is safe and is an implicit conversion, but is needed here to choose the correct overload of std::unique_ptr<>::reset):
m_name.reset(const_cast<char const*>(JniUtil::copyString(...).release()));

g++ ultra verbosity nightmare

This is for a single error. I had to cut it down in order to post it here. How to disable this madness ? (g++ 5.3.1)
user#computer:~/projectClient# ./build
project/update.cpp: In function ‘bool is_recentlyProcessed(IntervalTime, ulong)’:
project/update.cpp:71:80: error: no match for ‘operator==’ (operand types are ‘std::_Rb_tree_const_iterator<long unsigned int>’ and ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’)
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:312:7: note: candidate: bool std::_Rb_tree_const_iterator<_Tp>::operator==(const _Self&) const [with _Tp = long unsigned int; std::_Rb_tree_const_iterator<_Tp>::_Self = std::_Rb_tree_const_iterator<long unsigned int>]
operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/5/bits/stl_tree.h:312:7: note: no known conversion for argument 1 from ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’ to ‘const _Self& {aka const std::_Rb_tree_const_iterator<long unsigned int>&}’
In file included from /usr/include/c++/5/stack:61:0,
from /usr/include/jsoncpp/json/reader.h:15,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_stack.h:246:5: note: candidate: template<class _Tp, class _Seq> bool std::operator==(const std::stack<_Tp, _Seq>&, const std::stack<_Tp, _Seq>&)
operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
^
/usr/include/c++/5/bits/stl_stack.h:246:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::stack<_Tp, _Seq>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator==(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)
operator==(const deque<_Tp, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::deque<_Tp, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:272:5: note: candidate: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:272:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:265:5: note: candidate: template<class _Tp, class _Ref, class _Ptr> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:265:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:62:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:61:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_map.h:1073:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_map.h:1073:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: candidate: template<class _Tp> bool std::operator==(std::nullptr_t, const std::shared_ptr<_Tp1>&)
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: candidate: template<class _Tp> bool std::operator==(const std::shared_ptr<_Tp1>&, std::nullptr_t)
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: candidate: template<class _Tp1, class _Tp2> bool std::operator==(const std::shared_ptr<_Tp1>&, const std::shared_ptr<_Tp2>&)
operator==(const shared_ptr<_Tp1>& __a,
^
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(std::nullptr_t, const std::__shared_ptr<_Tp, _Lp>&)
operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp, _Lp>&, std::nullptr_t)
operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: candidate: template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp1, _Lp>&, const std::__shared_ptr<_Tp2, _Lp>&)
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
^
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:62:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
operator==(const multiset<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multiset<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:61:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_set.h:842:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
operator==(const set<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_set.h:842:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::set<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
....
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:134:5: note: candidate: template<class _Tp> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/5/bits/allocator.h:134:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:128:5: note: candidate: template<class _T1, class _T2> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/5/bits/allocator.h:128:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/char_traits.h:40:0,
from /usr/include/c++/5/string:40,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/postypes.h:216:5: note: candidate: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
/usr/include/c++/5/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::fpos<_StateT>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: candidate: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator==(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator==(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:342:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator==(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: candidate: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator==(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/utility:70:0,
from /usr/include/c++/5/algorithm:60,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:214:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/5/bits/stl_pair.h:214:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::pair<_T1, _T2>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
from /usr/include/c++/5/bits/allocator.h:46,
from /usr/include/c++/5/string:41,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/ext/new_allocator.h:139:5: note: candidate: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
^
/usr/include/c++/5/ext/new_allocator.h:139:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
user#computer:~/projectClient#
Here's the build command (it doesn't make a difference if i remove -Wall):
g++ -O3 -Wall -Wno-deprecated-declarations -Wno-unused-variable -Wno-format-contains-nul -std=c++11 -D${JSON} \
-lpthread -lboost_system -lboost_chrono -lssl -lcrypto -ljsoncpp \
-o bin/client client.cpp common.cpp update.cpp
While the error spew is daunting at initial glance, it can be helpful in tricky cases. Just start at the top and work your way down until you figure out what the problem is.
In this case it looks like you're trying to compare a std::_Rb_tree_const_iterator<long unsigned int> with a std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > > which are iterators to completely different types of objects.
It seems that find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) returns an interator to a different container than what recentlyProcessed.end is - note that recentlyProcessed.end doesn't have an index.
Probably you need to compare with recentlyProcessed[it].end or recentlyProcessed[it].end() instead.

Inserting an object of struct into a hash table C++

I'm currently working on a project involving hash tables. I've read in a text file into a vector of Symbol structs and I now have to insert these structs (objects, really) into a hash table. I was given a specific insertion function to use, however, I can't seem to get it to work. I've included the insertion function below as well as my Driver.cpp file which contains reading in the file to vector of structs and my attempt at inserting this into the hash table.
I would appreciate any help/feedback has to where I'm going wrong.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string>
#include <time.h>
#include <unistd.h>
#include "SeparateChaining.h"
using namespace std;
struct Symbol
{
int type;
string name;
};
size_t hash(const string & key); //declaration of hashing function
int main()
{
/************ VARS ***************/
string line;
int line_count;
int table_size;
int increment;
/************ Vector of Symbols ***************/
vector<Symbol> symbols;
/************ HashTable of Symbols ***************/
HashTable<Symbol> hashtable; //precomputed to have 101 elements --> probably will change this to accomodate table size.
cout << "Opening file..." << endl;
usleep(2000000);
ifstream file;
file.open("symbols.txt");
if(!file)
{
cout << "System failed to open file.";
}
else
{
cout << "File successfully opened" << endl;
}
cout << "Please enter the table size for the Hash Table. (NOTE: It MUST be a prime number.)" << endl;
cin >> table_size;
for(Symbol temp; file >> temp.name >> temp.type;)
{
symbols.push_back(temp);
increment++;
}
//Just to test and see if its loading it correctly...
for(int i = 0; i < symbols.size(); i++)
{
cout << symbols[i].name << endl;
cout << symbols[i].type << endl;
}
for(int j = 0; j < symbols.size(); j++)
{
hashtable.insert(symbols); // Messing up here !!!!!!!!!!!!!
}
//cout << ::hash("hi") << endl;
}
size_t hash( const string & key )
{
size_t hashVal = 0;
for( char ch : key )
hashVal = 37 * hashVal + ch;
return hashVal;
}
Insert function(s) in the SeparateChaining.h:
bool insert( const HashedObj & x )
{
auto & whichList = theLists[ myhash( x ) ];
if( find( begin( whichList ), end( whichList ), x ) != end( whichList) )
return false;
whichList.push_back( x );
// Rehash; see Section 5.5
if( ++currentSize > theLists.size( ) )
rehash( );
return true;
}
bool insert( HashedObj && x )
{
auto & whichList = theLists[ myhash( x ) ];
if( find( begin( whichList ), end( whichList ), x ) != end( whichList ) )
return false;
whichList.push_back( std::move( x ) );
// Rehash; see Section 5.5
if( ++currentSize > theLists.size( ) )
rehash( );
return true;
}
Errors when done as hashtable.insert(symbols):
Driver.cpp: In function 'int main()':
Driver.cpp:65:27: error: no matching function for call to 'HashTable<Symbol>::insert(std::vector<Symbol>&)'
Driver.cpp:65:27: note: candidates are:
In file included from Driver.cpp:8:0:
SeparateChaining.h:44:10: note: bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]
SeparateChaining.h:44:10: note: no known conversion for argument 1 from 'std::vector<Symbol>' to 'const Symbol&'
SeparateChaining.h:58:10: note: bool HashTable<HashedObj>::insert(HashedObj&&) [with HashedObj = Symbol]
SeparateChaining.h:58:10: note: no known conversion for argument 1 from 'std::vector<Symbol>' to 'Symbol&&'
Errors when done as hashtable.insert(symbols[j]) after incrementing through the vector:
In file included from /opt/local/include/gcc47/c++/bits/basic_string.h:3032:0,
from /opt/local/include/gcc47/c++/string:54,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/functional_hash.h: In instantiation of 'struct std::hash<Symbol>':
SeparateChaining.h:107:32: required from 'size_t HashTable<HashedObj>::myhash(const HashedObj&) const [with HashedObj = Symbol; size_t = long unsigned int]'
SeparateChaining.h:46:50: required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
Driver.cpp:65:30: required from here
/opt/local/include/gcc47/c++/bits/functional_hash.h:60:7: error: static assertion failed: std::hash is not specialized for this type
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h: In instantiation of '_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = std::_List_iterator<Symbol>; _Tp = Symbol]':
/opt/local/include/gcc47/c++/bits/stl_algo.h:4466:45: required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_List_iterator<Symbol>; _Tp = Symbol]'
SeparateChaining.h:47:9: required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
Driver.cpp:65:30: required from here
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: error: no match for 'operator==' in '__first.std::_List_iterator<_Tp>::operator*<Symbol>() == __val'
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: candidates are:
In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/functional:2382:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
/opt/local/include/gcc47/c++/functional:2382:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: cannot convert '__first.std::_List_iterator<_Tp>::operator*<Symbol>()' (type 'Symbol') to type 'std::nullptr_t'
In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/functional:2376:5: note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
/opt/local/include/gcc47/c++/functional:2376:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::function<_Res(_ArgTypes ...)>'
In file included from /opt/local/include/gcc47/c++/functional:56:0,
from /opt/local/include/gcc47/c++/bits/stl_algo.h:68,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/tuple:797:5: note: template<class ... _TElements, class ... _UElements> bool std::operator==(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
/opt/local/include/gcc47/c++/tuple:797:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::tuple<_Elements ...>'
In file included from /opt/local/include/gcc47/c++/random:51:0,
from /opt/local/include/gcc47/c++/bits/stl_algo.h:67,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
/opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::normal_distribution<_RealType>'
In file included from /opt/local/include/gcc47/c++/list:64:0,
from SeparateChaining.h:6,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
/opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::list<_Tp, _Alloc>'
In file included from /opt/local/include/gcc47/c++/list:64:0,
from SeparateChaining.h:6,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note: template<class _Val> bool std::operator==(const std::_List_iterator<_Tp>&, const std::_List_const_iterator<_Val>&)
/opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::_List_iterator<_Tp>'
In file included from /opt/local/include/gcc47/c++/vector:65:0,
from Driver.cpp:4:
/opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::vector<_Tp, _Alloc>'
In file included from /opt/local/include/gcc47/c++/bits/locale_facets.h:50:0,
from /opt/local/include/gcc47/c++/bits/basic_ios.h:39,
from /opt/local/include/gcc47/c++/ios:45,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: mismatched types 'const _CharT*' and 'Symbol'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2490:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2490:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2483:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2483:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /opt/local/include/gcc47/c++/string:43:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/allocator.h:124:5: note: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
/opt/local/include/gcc47/c++/bits/allocator.h:124:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::allocator<_CharT>'
In file included from /opt/local/include/gcc47/c++/string:43:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/allocator.h:119:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
/opt/local/include/gcc47/c++/bits/allocator.h:119:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::allocator<_CharT>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:65:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::pair<_T1, _T2>'
In file included from /opt/local/include/gcc47/c++/iosfwd:42:0,
from /opt/local/include/gcc47/c++/ios:39,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/opt/local/include/gcc47/c++/bits/postypes.h:218:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::fpos<_StateT>'
Try
hashtable.insert(symbols[j]);
Also, you don't use increment, line_count or table_size, you just set them.
Explanation:
You're trying to insert the whole vector, not its elements, hence the datatype mismatch. By using array notation, you grab the actual element you want to insert.
Why do you even use the vector instead of inserting your symbols directly into the hash table?