GCC:抱歉,未实现:损坏过载

发布于 2024-12-17 04:16:04 字数 3996 浏览 3 评论 0原文

我得到了一段代码的编译错误(抱歉,未实现:重整过载),据我所知,这是正确的。我尝试将代码最小化为易于管理的示例,但它仍然很长(对此感到抱歉)。我知道其中的 C++11 内容正在开发中,所以这可能是我的编译器(GCC 4.6.2)的问题,但也可能是我遗漏了一些东西。

mod 函数只是更复杂函数(具有不同返回类型)的占位符。实际代码的目的是提供数据结构集合的索引,以允许使用不同的匹配标准进行快速查找。

干杯
马库斯

#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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2024-12-24 04:16:04

当问题出在编译器而不是代码时,GCC 的错误消息仅使用短语“抱歉,未实现”——在这种情况下,您正尝试使用尚未完全支持的 C++11 功能。

不幸的是,GCC 的网站不允许我 grep 特定错误消息的代码,因此我无法帮助您准确找出未实现的内容。我赞同 Basile 的建议,询问[电子邮件受保护]

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 [email protected].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文