Inserting an object of struct into a hash table C++ - 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?

Related

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.

Implementing custom iterator to work with std::find

I'm trying to implement a custom doubly linked list which works with std::find and other algorithms, I made a iterator for it which works with for loop however it does not work and is giving me a lot of errors, where do you think my problem is?
here is my simplified code:
template<typename T, class Allocator = std::allocator<T>>
class MyList {
private:
class Link {
public:
T item;
std::shared_ptr<Link> next; // next item
std::shared_ptr<Link> prev; // previous item
};
std::shared_ptr<Link> head;
std::shared_ptr<Link> tail;
public:
using allocator_type = Allocator;
using reference_link = T &;
class iterator {
public:
typedef iterator self_type;
typedef Link value_type;
typedef Link &reference;
typedef std::shared_ptr<Link> pointer;
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
iterator(pointer ptr) : _link(ptr) { }
self_type operator++() {
std::shared_ptr<Link> temp{new Link};
if (_link->next) {
temp->item = _link->next->item;
temp->next = _link->next->next;
temp->prev = _link->next->prev;
}
else {
temp->next = nullptr;
temp->prev = _link->prev->next;
}
this->_link = temp;
return *this;
}
self_type operator++(int junk) {
std::shared_ptr<Link> temp{new Link};
if (_link->next) {
temp->item = _link->next->item;
temp->next = _link->next->next;
temp->prev = _link->next->prev;
}
else {
temp->next = nullptr;
temp->prev = _link->prev->next;
}
this->_link = temp;
return *this;
}
reference operator*() { return *_link; }
pointer operator->() { return _link; }
bool operator==(const self_type &l) const {
if (_link->next == l._link->next && _link->prev == l._link->prev && _link->item == l._link->item) {
return true;
}
return false;
}
bool operator!=(const self_type &l) const {
return !operator==(l);
}
friend bool operator==(const iterator &lhs, const T &rhs) {
if (lhs->item == rhs) {
return true;
}
return false;
};
private:
pointer _link;
};
iterator begin();
iterator end();
using iterator = iterator;
using const_iterator = const iterator;
};
template<typename T, class Allocator>
typename MyList<T, Allocator>::iterator MyList<T, Allocator>::begin() {
return iterator{tail};
}
template<typename T, class Allocator>
typename MyList<T, Allocator>::iterator MyList<T, Allocator>::end() {
return (iterator{head})++;
}
This one works fine:
MyList<int, std::allocator<int>> m_list{1, 2, 3,};
for (MyList<int, std::allocator<int>>::iterator i = m_list.begin();
i != m_list.end(); ++i) {
std::cout << i->item;
}
but this gives me many error:
auto result1 = std::find(m_list.begin(), m_list.end(), 3 );
Which some are these:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = MyList<int, std::allocator<int> >::iterator; _Tp = int]’:
/usr/include/c++/4.8/bits/stl_algo.h:4441:45: required from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = MyList<int, std::allocator<int> >::iterator; _Tp = int]’
/home/epezhman/cpp/Part1/assignment4/src/main.cpp:44:63: required from here
/usr/include/c++/4.8/bits/stl_algo.h:139:46: error: no match for ‘operator==’ (operand types are ‘MyList<int, std::allocator<int> >::Link’ and ‘const int’)
while (__first != __last && !(*__first == __val))
^
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: candidates are:
In file included from /usr/include/c++/4.8/random:52:0,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/random.tcc:2030:5: note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
operator==(const std::normal_distribution<_RealType>& __d1,
^
/usr/include/c++/4.8/bits/random.tcc:2030:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::normal_distribution<_RealType>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/vector:64:0,
from /usr/include/c++/4.8/bits/random.h:34,
from /usr/include/c++/4.8/random:50,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_vector.h:1404:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8/bits/stl_vector.h:1404:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::vector<_Tp, _Alloc>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/iterator:66:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:4,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stream_iterator.h:130:5: note: template<class _Tp, class _CharT, class _Traits, class _Dist> bool std::operator==(const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&, const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&)
operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
^
/usr/include/c++/4.8/bits/stream_iterator.h:130:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/locale_facets.h:48:0,
from /usr/include/c++/4.8/bits/basic_ios.h:37,
from /usr/include/c++/4.8/ios:44,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:2,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
^
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:338:5: note: 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++/4.8/bits/shared_ptr.h:338:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:333:5: note: 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++/4.8/bits/shared_ptr.h:333:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::shared_ptr<_Tp1>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:327:5: note: 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++/4.8/bits/shared_ptr.h:327:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::shared_ptr<_Tp1>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1040:5: note: 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++/4.8/bits/shared_ptr_base.h:1040:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1035:5: note: 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++/4.8/bits/shared_ptr_base.h:1035:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1029:5: note: 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++/4.8/bits/shared_ptr_base.h:1029:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:500:5: note: template<class _Tp, class _Dp> bool std::operator==(std::nullptr_t, const std::unique_ptr<_Tp, _Dp>&)
operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
^
/usr/include/c++/4.8/bits/unique_ptr.h:500:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:495:5: note: template<class _Tp, class _Dp> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, std::nullptr_t)
operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
^
/usr/include/c++/4.8/bits/unique_ptr.h:495:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:489:5: note: template<class _Tp, class _Dp, class _Up, class _Ep> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, const std::unique_ptr<_Up, _Ep>&)
operator==(const unique_ptr<_Tp, _Dp>& __x,
^
/usr/include/c++/4.8/bits/unique_ptr.h:489:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:79:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/functional:2543:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
^
/usr/include/c++/4.8/functional:2543:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:79:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/functional:2537:5: note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
^
/usr/include/c++/4.8/functional:2537:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::function<_Res(_ArgTypes ...)>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/functional:55:0,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/tuple:813:5: note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator==(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
operator==(const tuple<_TElements...>& __t,
^
/usr/include/c++/4.8/tuple:813:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::tuple<_Elements ...>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/tuple:39:0,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/array:228:5: note: 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>& __one, const array<_Tp, _Nm>& __two)
^
/usr/include/c++/4.8/array:228:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::array<_Tp, _Nm>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: 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,
^
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator==(const _CharT* __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: mismatched types ‘const _CharT*’ and ‘MyList<int, std::allocator<int> >::Link’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2493: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>&)
operator==(const basic_string<_CharT>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2493:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::basic_string<_CharT>’
while (__first != __last && !(*__first == __val))
It looks like your value_type and reference should use T not Link. (You want to iterate over the values, not the links containing them.) operator * and operator -> need to change appropriately.

Error while copying one vector to other c++

I have overloaded allocator for most of the stl containers below is the code. The code is from here
#include <iostream>
#include <vector>
#include <list>
namespace outside
{
template<typename T>
struct MyAllocator
{
typedef typename std::allocator<T>::value_type value_type;
typedef typename std::allocator<T>::pointer pointer;
typedef typename std::allocator<T>::const_pointer const_pointer;
typedef typename std::allocator<T>::reference reference;
typedef typename std::allocator<T>::const_reference const_reference;
typedef typename std::allocator<T>::size_type size_type;
pointer allocate (size_type n, typename std::allocator<void>::const_pointer hint=0)
{
std::cerr << "allocate..." << std::endl;
return std::allocator<T>{}.allocate(n, hint);
}
void deallocate (pointer p, size_type n)
{
std::cerr << "deallocate..." << std::endl;
return std::allocator<T>{}.deallocate(p, n);
}
template <class Type> struct rebind
{
typedef MyAllocator<Type> other;
};
MyAllocator()
{
}
MyAllocator(const MyAllocator<T>& other )
{
}
template< class U >
MyAllocator( const MyAllocator<U>& other )
{
}
};
} // namespace outside
namespace outer
{
template<class T>
using vector = ::std::vector<T, outside::MyAllocator<T>>;
template<class T>
using list = ::std::list<T, outside::MyAllocator<T>>;
}
int main()
{
outer::vector<int> myVector1;
outer::vector<int> myVector2;
myVector1.push_back(10);
myVector1.push_back(20);
// myVector2 = myVector1; // Getting compilation error
for (auto i = myVector1.begin(); i != myVector1.end(); ++i) {
std::cout << *i << ' ';
}
std::list<int> myList1;
std::list<int> myList2;
myList2 = myList1; // // No compilation error
}
Copying one vector to another vector is giving me error. While for the same code copying one list to another list is working fine.
Compilation error
included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc: In instantiation of 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = outside::MyAllocator<int>]':
prog.cpp:59:15: required from here
/usr/include/c++/5/bits/vector.tcc:176:37: error: no match for 'operator!=' (operand types are 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' and 'const _Tp_alloc_type {aka const outside::MyAllocator<int>}')
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/iosfwd:40:0,
from /usr/include/c++/5/ios:38,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/postypes.h:221: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:221:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::fpos<_StateT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:227: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:227:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::pair<_T1, _T2>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:304: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:304:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::reverse_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:354: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:354:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::reverse_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1077: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:1077:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::move_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1083: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:1083:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::move_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/allocator.h:140:5: note: candidate: template<class _T1, class _T2> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_T2>&)
operator!=(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/5/bits/allocator.h:140:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::allocator<_CharT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/allocator.h:146:5: note: candidate: template<class _Tp> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/5/bits/allocator.h:146:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::allocator<_CharT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4948: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,
^
/usr/include/c++/5/bits/basic_string.h:4948:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4960: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,
^
/usr/include/c++/5/bits/basic_string.h:4960:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: mismatched types 'const _CharT*' and 'outside::MyAllocator<int>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4972: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,
^
/usr/include/c++/5/bits/basic_string.h:4972:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/ios_base.h:46:0,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/system_error:311:3: note: candidate: bool std::operator!=(const std::error_code&, const std::error_code&)
operator!=(const error_code& __lhs, const error_code& __rhs) noexcept
^
/usr/include/c++/5/system_error:311:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_code&'
/usr/include/c++/5/system_error:315:3: note: candidate: bool std::operator!=(const std::error_code&, const std::error_condition&)
operator!=(const error_code& __lhs, const error_condition& __rhs) noexcept
^
/usr/include/c++/5/system_error:315:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_code&'
/usr/include/c++/5/system_error:319:3: note: candidate: bool std::operator!=(const std::error_condition&, const std::error_code&)
operator!=(const error_condition& __lhs, const error_code& __rhs) noexcept
^
/usr/include/c++/5/system_error:319:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_condition&'
/usr/include/c++/5/system_error:323:3: note: candidate: bool std::operator!=(const std::error_condition&, const std::error_condition&)
operator!=(const error_condition& __lhs,
^
/usr/include/c++/5/system_error:323:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_condition&'
In file included from /usr/include/c++/5/bits/locale_facets.h:48:0,
from /usr/include/c++/5/bits/basic_ios.h:37,
from /usr/include/c++/5/ios:44,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/streambuf_iterator.h:210:5: note: candidate: template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
^
/usr/include/c++/5/bits/streambuf_iterator.h:210:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/vector:64:0,
from prog.cpp:2:
/usr/include/c++/5/bits/stl_vector.h:1535:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/5/bits/stl_vector.h:1535:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::vector<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/list:63:0,
from prog.cpp:3:
/usr/include/c++/5/bits/stl_list.h:291:5: note: candidate: template<class _Val> bool std::operator!=(const std::_List_iterator<_Tp>&, const std::_List_const_iterator<_Val>&)
operator!=(const _List_iterator<_Val>& __x,
^
/usr/include/c++/5/bits/stl_list.h:291:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::_List_iterator<_Tp>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/list:63:0,
from prog.cpp:3:
/usr/include/c++/5/bits/stl_list.h:1843:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
^
/usr/include/c++/5/bits/stl_list.h:1843:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::list<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
I am trying to understand why this is the case and solution for this problem ?
The key part of the exception is hundreds of lines into it:
In file included from /usr/local/include/c++/5.2.0/vector:64:0,
from main.cpp:2: /usr/local/include/c++/5.2.0/bits/stl_vector.h:1535:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/local/include/c++/5.2.0/bits/stl_vector.h:1535:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.2.0/vector:69:0,
from main.cpp:2:
/usr/local/include/c++/5.2.0/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::vector<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
vector::operator= requires vector::operator!=, which requires allocator::operator!=, which doesn't exist. Without it, the function can't be created. Simply add an operator!= to your allocator. While you're at it, also make sure you have all the other required allocator functions. If memory serves me right, you're missing a fair number.
Change the definition to struct MyAllocator: public std::allocator<T> and the code will compile.

GCC: Why does an error in one line of code (comparison of string and NULL) cause a long list of error messages?

I've been curious about why one error can cause the compiler to generate a very long list of error messages. The following example is the result of an erroneous comparison between an element of a vector<string> and NULL at line 100 of main.cpp under GCC 4.8.1:
> g++ -g3 -std=c++11 main.cpp functions.cpp
main.cpp: In function ‘int main()’:
main.cpp:100:24: error: no match for ‘operator==’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ and ‘long int’)
if(args[1] == NULL) {
^
main.cpp:100:24: note: candidates are:
In file included from /usr/include/c++/4.8/iosfwd:40:0,
from /usr/include/c++/4.8/ios:38,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/postypes.h:216:5: note: 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++/4.8/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::fpos<_StateT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_pair.h:214:5: note: 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++/4.8/bits/stl_pair.h:214:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::pair<_T1, _T2>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:291:5: note: 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++/4.8/bits/stl_iterator.h:291:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:341:5: note: 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++/4.8/bits/stl_iterator.h:341:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:1031:5: note: 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++/4.8/bits/stl_iterator.h:1031:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::move_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:1037:5: note: 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++/4.8/bits/stl_iterator.h:1037:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::move_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:41:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/allocator.h:128:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
operator==(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/4.8/bits/allocator.h:128:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::allocator<_CharT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:41:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/allocator.h:133:5: note: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/4.8/bits/allocator.h:133:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::allocator<_CharT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2486: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>&)
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2486:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2493: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>&)
operator==(const basic_string<_CharT>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2493:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const std::basic_string<_CharT>’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator==(const _CharT* __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const _CharT*’ and ‘std::basic_string<char>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: 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,
^
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const _CharT*’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/locale_facets.h:48:0,
from /usr/include/c++/4.8/bits/basic_ios.h:37,
from /usr/include/c++/4.8/ios:44,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
^
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/vector:64:0,
from main.h:16,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_vector.h:1403:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8/bits/stl_vector.h:1403:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::vector<_Tp, _Alloc>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/x86_64-suse-linux/bits/c++allocator.h:33:0,
from /usr/include/c++/4.8/bits/allocator.h:46,
from /usr/include/c++/4.8/string:41,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/ext/new_allocator.h:139:5: note: 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++/4.8/ext/new_allocator.h:139:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:811:5: note: 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++/4.8/bits/stl_iterator.h:811:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:805:5: note: 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++/4.8/bits/stl_iterator.h:805:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
if(args[1] == NULL) {
^
This can make it very hard to understand the problem. What is the reason for this behavior?
If you have an expression of the form vec == NULL, the compiler applies ADL to find an appropriate operator== to call. If it can't find a single one it outputs all operator== candidates found in all namespaces considered, and the reason they did not fit here.
One of those can look like this:
In file included from [..] main.cpp:12:
[..]:216:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
[..]:216:5: note: template argument deduction/substitution failed:
In file included from [..] main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::fpos<_StateT>’
if(args[1] == NULL) {
^
We couldn't match the first parameter to the first argument as std::string isn't derived from any fpos-specialization (also std::string doesn't have any appropriate conversion operators, but that isn't mentioned here). If you defined an operator== that can't be found/called, wouldn't you like to know the reason from the compilers view? (Especially if you don't have a clue yourself)
This can be very useful at times. When it isn't, ignore it. In most cases C++-programmers immediately see and understand what causes the error message (and its enourmos note-section).
This may help in situations like this (you got a large volume of template related message).
Whether your are using make or directly using the compiler, try to pipe the stderr to a file in my example
make 2> error.log
The use any editor open the error.log file. Search for file name of the source code you wrote. There should only be one or two lines that are interesting to you. For example:
mysourcefile.cpp:51:20: required from here
This is where the problem happened; look harder here.

std::count errors

temp_holder.clear();
temp_holder << n;
n_str = temp_holder.str();
int f = count(n_str.begin(), n_str.end(), a);
That's my code, and this is g++ output:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h: In instantiation of ‘typename std::iterator_traits<_InputIterator>::difference_type std::count(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _Tp = std::basic_string<char>; typename std::iterator_traits<_InputIterator>::difference_type = long int]’:
trintatres.cpp:44:50: required from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<char*, std::basic_string<char> >() == __value’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: candidates are:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iosfwd:42:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:39,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/postypes.h:218:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::fpos<_StateT>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:65:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:212:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:212:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::pair<_T1, _T2>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:293:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:293:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::reverse_iterator<_Iterator>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:343:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::reverse_iterator<_IteratorL>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:119:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:119:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::allocator<_T1>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:124:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:124:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::allocator<_Tp1>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2483:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2490:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2504:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const _CharT*’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/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*)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2516:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_facets.h:50:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_ios.h:39,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:45,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/streambuf_iterator.h:206:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::istreambuf_iterator<_CharT, _Traits>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu/bits/c++allocator.h:34:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:48,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/new_allocator.h:129:5: note: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/new_allocator.h:129:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::new_allocator<_Tp>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:813:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:813:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:807:5: note: 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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:807:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ and ‘char’
I honestly think I'm using std::count from correctly, according to cplusplus.com.
Any idea of what I'm doing wrong?
EDIT
Full code:
#include <iostream>
#include <string>
#include <sstream>
#include <climits>
#include <algorithm>
using namespace std;
int max(int a, int b) {
return (a > b) ? a : b;
}
int main() {
string a;
cin >> a;
int c;
cin >> c;
int q;
cin >> q;
string cases[q];
int max_case = INT_MIN;
int temp;
for (int i = 0; i < q; i++) {
cin >> temp;
max_case = max(temp, max_case);
stringstream current_case_holder;
current_case_holder << temp;
cases[i] = current_case_holder.str();
}
int sequence[max_case];
int n;
stringstream temp_holder;
string n_str;
for (int i = 0; i < max_case; i++) {
n = 1;
while (true) {
temp_holder.clear();
temp_holder << n;
n_str = temp_holder.str();
int f = count(n_str.begin(), n_str.end(), a);
//}
n++;
}
}
return 0;
}
The first error tells you all you need to know:
In instantiation of ‘typename std::iterator_traits<_InputIterator>::difference_type std::count(_IIter, _IIter, const _Tp&)
[with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >;
_Tp = std::basic_string<char>;
typename std::iterator_traits<_InputIterator>::difference_type = long int]’
This indicates that you're passing a std::string object for the third argument to std::count, which is wrong; you need to pass a char object instead, since you're effectively iterating over a std::string, and std::string::value_type is char.