抱歉,未实现:mangling过载
GCC: sorry, unimplemented: mangling overload
对于一段据我所知是正确的代码,我得到了这个编译错误(对不起,未实现:mangling overload)。我试图将代码最小化到一个可管理的示例,但它仍然很长(抱歉)。我知道c++ 11的东西在开发中,所以这可能是我的编译器(GCC 4.6.2)的问题,但也可能是我遗漏了一些东西。
模态函数仅仅是更复杂函数(具有不同返回类型)的占位符。实际代码的目的是在一组数据结构上提供索引,以便使用不同的匹配标准进行快速查找。
欢呼马库斯
#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的错误消息才会使用短语"对不起,未实现"——在这种情况下,你正在尝试使用尚未完全支持的c++ 11特性。
不幸的是,GCC的网站不允许我搜索特定错误消息的代码,因此我无法帮助您准确地找出没有实现的内容。我赞同Basile在gcc-help@gcc.gnu.org上提问的建议。
相关文章:
- ostream过载时的缓冲区冲洗
- gcc和c++17的过载解析失败
- C++Cast运算符过载
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 过载'operator new'如何导致无限循环?
- "Inverse SFINAE"避免模棱两可的过载
- 操作员C++的模棱两可的过载
- C++中>>操作员过载时出现问题?
- 基于返回类型的转换和过载扣除
- 没有可行的过载'='错误,可能导致这种情况的原因是什么?
- 是否存在包含负号的isdigit函数(过载)
- C++许多 SFINAE 风格的过载
- C++函数过载会导致 SEG 故障
- SFINAE不能防止模棱两可的操作员过载吗?
- 如何解决不明确的运算符过载问题?
- 屏幕插入运算符<<的运算符过载问题
- ostream 运算符<< 为获取 STL 容器而过载,传递 std::string 会破坏它?
- 在这种情况下是私有的吗?试图使操作员<<过载
- C++操作员过载>>
- 抱歉,未实现:mangling过载