Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcpp set definition incomplete for KeyComparator, ValueComparator #3251

GregoryMorse opened this issue Nov 28, 2019 · 0 comments

libcpp set definition incomplete for KeyComparator, ValueComparator #3251

GregoryMorse opened this issue Nov 28, 2019 · 0 comments


Copy link

@GregoryMorse GregoryMorse commented Nov 28, 2019

In source file here:

I see no reason the KeyComparator and ValueComparator operations and template parameters omitted.

It means anyone wishing to use these which can be a fairly normal use case, one has to do something like I have done as follows:

from libcpp.utility cimport pair

cdef extern from "<set>" namespace "std" nogil:
    cdef cppclass set[T, KC]:
        ctypedef T value_type
        cppclass iterator:
            T& operator*()
            iterator operator++()
            iterator operator--()
            bint operator==(iterator)
            bint operator!=(iterator)
        cppclass reverse_iterator:
            T& operator*()
            iterator operator++()
            iterator operator--()
            bint operator==(reverse_iterator)
            bint operator!=(reverse_iterator)
        cppclass const_iterator(iterator):
        cppclass const_reverse_iterator(reverse_iterator):
        set() except +
        set(set&) except +
        #set& operator=(set&)
        bint operator==(set&, set&)
        bint operator!=(set&, set&)
        bint operator<(set&, set&)
        bint operator>(set&, set&)
        bint operator<=(set&, set&)
        bint operator>=(set&, set&)
        iterator begin()
        const_iterator const_begin "begin"()
        void clear()
        size_t count(const T&)
        bint empty()
        iterator end()
        const_iterator const_end "end"()
        pair[iterator, iterator] equal_range(const T&)
        #pair[const_iterator, const_iterator] equal_range(T&)
        iterator erase(iterator)
        iterator erase(iterator, iterator)
        size_t erase(T&)
        iterator find(T&)
        const_iterator const_find "find"(T&)
        pair[iterator, bint] insert(const T&) except +
        iterator insert(iterator, const T&) except +
        void insert(iterator, iterator) except +
        #key_compare key_comp()
        iterator lower_bound(T&)
        const_iterator const_lower_bound "lower_bound"(T&)
        size_t max_size()
        reverse_iterator rbegin()
        const_reverse_iterator const_rbegin "rbegin"()
        reverse_iterator rend()
        const_reverse_iterator const_rend "rend"()
        size_t size()
        void swap(set&)
        iterator upper_bound(const T&)
        const_iterator const_upper_bound "upper_bound"(const T&)
        #value_compare value_comp()

ctypedef Node* Node_ptr
ctypedef bool(*node_comp)(const Node_ptr& lhs, const Node_ptr& rhs)
cdef bool node_comparator(const Node_ptr& lhs, const Node_ptr& rhs):
    return <object> < <object>

cdef struct Node:
  set[Node_ptr, node_comp]* children
  bint flag_last
  void* data

cdef Node* construct_node(void* data):
  cdef Node* n
  n = <Node*>PyMem_Malloc(sizeof(Node))
  if not n: raise MemoryError()
  deref(n).children = new set[Node_ptr, node_comp](node_comparator)
  deref(n).flag_last = False
  deref(n).data = data
  return n
cdef void destruct_node(Node* n):
  for x in deref(n.children):
  del n.children

I think there is a way to provide a default template parameter for this and ValueComparator is not needed as its the same. Can this be modified to make it into the standard Cython includes? Or is there something I am missing here for why it is left out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.