why do I need comparison operators in boost python vector indexing suite?

那年仲夏 提交于 2019-12-05 07:41:21

vector_indexing_suite implements a __contains__ member function, which requires the presence of an equality operator. As a consequence, your type must provide such an operator.

The sandbox version of Boost.Python solve this issue by using traits to determine what kind of operations are available on containers. For instance, find will only be provided if the values are equality comparable.

By default, Boost.Python consider all values to be equality comparable and less-than comparable. Since your type does not meet these requirements, you need to specialize the traits to specify what operations it supports:

namespace indexing {
  template<>
  struct value_traits<A> : public value_traits<int>
  {
    static bool const equality_comparable = false;
    static bool const lessthan_comparable = false;
  };
}

This is documented here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!