I get this compile error (sorry, unimplemented: mangling overload) for a piece of code that is, as far as I can tell, correct. I have tried to minimize the code to a manageable example, but it’s still quite long (sorry about that). I know the C++11 stuff in there are under development, so it might be a problem with my compiler (GCC 4.6.2), but it might also be me missing something.
The mod-functions are merely placeholders for more complex functions (with different return types). The purpose of the real code is to provide indices over a collection of data structures, to allow fast look-up using different matching criteria.
Cheers
Markus
#include <map>
#include <string>
#include <iostream>
#include <list>
#include <functional>
#include <cassert>
//
// Functions
//
struct mod2 : public std::unary_function<int, int> {
int operator()(int x) const { return x % 2; }
};
struct mod3 : public std::unary_function<int, int> {
int operator()(int x) const { return x % 3; }
};
struct mod4 : public std::unary_function<int, int> {
int operator()(int x) const { return x % 4; }
};
//
// Base class foo
//
struct foo {
std::vector<int> data_m;
foo() : data_m() {}
int& insert(int x) {
data_m.push_back(x);
return data_m.back();
}
template<typename trans_T>
std::list<std::pair<typename trans_T::result_type, int> >
match(const typename trans_T::result_type& pattern,
const trans_T& trans = trans_T()) const {
std::list<std::pair<typename trans_T::result_type, int> > results;
for (auto it = data_m.begin(); it != data_m.end(); ++it) {
auto p = trans(*it);
if (pattern == p) {
results.push_back(std::make_pair(p, *it));
}
}
return results;
}
};
//
// Derived class bar
//
template<typename base_T, typename trans_T>
struct bar : public base_T {
typedef base_T base_type;
typedef std::multimap<typename trans_T::result_type, int> index_type;
index_type index_m;
bar(const trans_T& trans = trans_T()) : base_type(), index_m() {}
int& insert(int x, const trans_T& trans = trans_T()) {
return index_m.insert(typename index_type::value_type(trans(x), base_type::insert(x)))->second;
}
std::pair<typename index_type::const_iterator,
typename index_type::const_iterator>
match(const typename trans_T::result_type& pattern,
const trans_T& trans = trans_T()) const {
return index_m.equal_range(pattern);
}
template<typename xtrans_T>
decltype(base_type().match(typename xtrans_T::result_type(), xtrans_T()))
match(const typename xtrans_T::result_type& pattern,
const xtrans_T& xtrans = xtrans_T()) const {
return base_type::match(pattern, xtrans);
}
};
//
// Begin/end functions present in Boost but not in GCC
//
template<typename iter_T>
iter_T begin(const std::pair<iter_T, iter_T>& range) {
return range.first;
}
template<typename iter_T>
iter_T end(const std::pair<iter_T, iter_T>& range) {
return range.second;
}
//
// Main
//
int main(const int argc, const char** argv) {
using std::cout;
using std::endl;
bar<bar<foo, mod2>, mod3> baz;
///
/// Insert some numbers
///
for (int i = 0; i < 20; ++i) {
baz.insert(i);
}
for (int i = 0; i < 5; ++i) {
cout << "i = " << i << endl;
///
/// Try to match with different functions
///
auto baz_match_mod2 = baz.match(i, mod2());
cout << "mod2:";
for (auto it = begin(baz_match_mod2); it != end(baz_match_mod2); ++it) {
assert(it->first == i);
cout << ' ' << it->second;
}
cout << endl;
auto baz_match_mod3 = baz.match(i, mod3());
cout << "mod3:";
for (auto it = begin(baz_match_mod3); it != end(baz_match_mod3); ++it) {
assert(it->first == i);
cout << ' ' << it->second;
}
cout << endl;
auto baz_match_mod4 = baz.match(i, mod4());
cout << "mod4:";
for (auto it = begin(baz_match_mod4); it != end(baz_match_mod4); ++it) {
assert(it->first == i);
cout << ' ' << it->second;
}
cout << endl;
}
return 0;
}
GCC’s error messages only use the phrase “sorry, unimplemented” when the problem is with the compiler, not with your code — in this case, you are trying to make use of a C++11 feature that is not yet fully supported.
Unfortunately, GCC’s website doesn’t let me grep the code for that particular error message, so I can’t help you figure out exactly what is not implemented. I second Basile’s recommendation to ask on gcc-help@gcc.gnu.org.