带有==运算符的struct vector上的C ++ upper_bound

时间:2016-10-31 15:39:57

标签: c++ c++11 stl

我有以下结构,

struct cube
{
    int  index l , b , h;
    bool operator<(const cube & c2) const
    {
        if (l == c2.l && b == c2.b && h == c2.h)
            return index < c2.index;
        if (l == c2.l && b == c2.b)
            return h < c2.h;
        if (l == c2.l )
            return b < c2.b;
        return l < c2.l;
    }
    bool operator==(const cube  c2) 
    {
        return index != c2.index && l == c2.l && b == c2.b;
    }
};

现在我想根据==运算符中的条件在此结构的向量上应用upper_bound。
但是,它仍然返回那些索引相同的迭代器

int pos2 = upper_bound(v.begin(),v.end(),v[i]) - v.begin();

即v [i] .index等于v [pos2] .index

1 个答案:

答案 0 :(得分:0)

cube也是foo时,bar foo < bar true foo == bar true实例可能index == c2.index && l == c2.l && b == c2.b operator== 。您可以通过在std::upper_bound中将operator<写为返回的表达式来解决此问题。

这个矛盾是您问题的根本原因,但请注意index本身只需要cube正确实施;你的是。

cube集合的属性不是cube而是给定的@api.multi def button_generate_wh_doc(self): context = self._context partner = self.env['res.partner'] res = {} for inv in self: view_id = self.env['ir.ui.view'].search([ ('name', '=', 'account.invoice.wh.iva.customer')]) context = self.env.context.copy() context.update({'domain':[( ('invoice_id','=',inv.id) ('type','=',inv.type) ('default_partner_id','=', partner._find_accounting_partner( inv.partner_id).id) ('default_name' ,'=', inv.name or inv.number) ('view_id' ,'=', view_id))]}) res = { 'name': _('Withholding vat customer'), 'type': 'ir.actions.act_window', 'res_model': 'account.wh.iva', 'view_type': 'form', 'view_id': False, 'view_mode': 'form', 'nodestroy': True, 'target': 'current', 'domain': "[('type', '=', '" + inv.type + "')]", 'context': context } return res 吗?也就是说,它不应出现在Odoo Server Error Traceback (most recent call last): File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 544, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 581, in dispatch result = self._call_function(**self.params) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 317, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/service/model.py", line 118, in wrapper return f(dbname, *args, **kwargs) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 314, in checked_call return self.endpoint(*a, **kw) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 810, in __call__ return self.method(*args, **kw) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 410, in response_wrap response = f(*args, **kw) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/addons/web/controllers/main.py", line 948, in call_button action = self._call_kw(model, method, args, {}) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/addons/web/controllers/main.py", line 936, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/api.py", line 268, in wrapper return old_api(self, *args, **kwargs) File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/api.py", line 399, in old_api result = method(recs, *args, **kwargs) File "/home/kristian/odoov8/odoo-venezuela/l10n_ve_withholding_iva/model/invoice.py", line 424, in button_generate_wh_doc ('type','=',inv.type) TypeError: 'tuple' object is not callable 类?