I am trying to call the overloaded member function of table::scan_index(std::string, ...) without success. For clarity, I deleted all the inappropriate code.
I have a class called table that has an overloaded / templated member function called scan_index() to treat rows as a special case.
class table : boost::noncopyable { public: template <typename T> void scan_index(T val, std::function<bool (uint recno, T val)> callback) {
Then there is a hitlist class that has several template member functions that call table::scan_index(T, ...)
class hitlist { public: template <typename T> void eq(uint fieldno, T value) { table* index_table = db.get_index_table(fieldno); // code index_table->scan_index<T>(value, [&](uint recno, T n)->bool { // code }); } };
And finally, the code that discards all of this:
hitlist hl; // code hl.eq<std::string>(*fieldno, p1.to_string());
The problem is that instead of calling table::scan_index(std::string, ...) it calls the template version. I tried to use both overload (as shown above) and a specialized function template (below), but nothing works. After looking at this code for several hours, I feel like I'm missing something obvious. Any ideas?
template <> void scan_index<std::string>(std::string val, std::function<bool (uint recno, std::string val)> callback) {
Update: I reset the <T> decoration from the scan_index() call. As a result, it turned out that calls with the string parameter are just fine, but calls with other types (for example, double) led to the following error:
cannot convert parameter 1 from 'double' to 'std::string'
So, I returned to using specialized specialization. Now I get this error:
error C2784: 'void table::scan_index(T,std::tr1::function<bool(uint,T)>)' : could not deduce template argument for 'std::tr1::function<bool(uint,T)>' from '`anonymous-namespace'::<lambda5>'
FYI: I am using VC ++ 10.0
Solution: I fixed this problem by dropping the scan_index() template function from the table class and simply writing down four overloaded functions (three of which are identical, except for the signature). Fortunately, they are all quite short (less than ten lines), so this is not so bad.