海湾合作委员会:对不起,没有实施:错误超载

时间:2011-11-22 06:36:45

标签: c++ templates compiler-errors g++ c++11

对于一段代码,我得到了这个编译错误(对不起,未实现:修复重载),据我所知,这是正确的。我试图将代码最小化为一个可管理的示例,但它仍然很长(抱歉)。我知道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;
}

1 个答案:

答案 0 :(得分:1)

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

不幸的是,GCC的网站不允许我为特定的错误消息编写代码,所以我无法帮助你弄清楚究竟是什么没有实现。我是第二个Basile的建议,请发送电子邮件至gcc-help@gcc.gnu.org。