question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support "in" operator for STL containers

See original GitHub issue

This is a feature request for supporting python-like “in” operator for STL containers (vector, map, etc.)

For example to test whether a set contains a value in python:

a = set([1, 2])
assert 1 in a

But right now similar operator in Cython is not supported:

from libcpp.set cimport set
cdef set a = [1, 2]
assert 1 in a

The compiler will complain Invalid types for 'in' or Invalid types for 'not_in'

This is not critically necessary but it’s useful

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
da-woodscommented, Oct 23, 2022

Thanks @jhelgert - I suspect practically we’d want to support C++97 still for this (it seems like kind of a basic feature to require C++20 for).

I actually think this is easier than Scoder says and it’s a very small number of template functions rather than needing generated code. I’ll have a look at this sometime fairly soon.

1reaction
jhelgertcommented, Oct 23, 2022

Just stumbled upon this. I think it’s worth mentioning that C++20 added .contains() methods for all the associated STL containers (map, multimap, set, multiset and the _unordered ones) making this less verbose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overloading operator<<() for stl containers - c++
I have searched in the internet and SO to find if there is a way to overload operator<<() for stl containers. I have...
Read more >
Containers library - cppreference.com
each of which is designed to support a different set of operations. The container ... Note that std::unordered_map::operator[] also counts, ...
Read more >
Containers - CPlusPlus.com
Containers replicate structures very commonly used in programming: dynamic arrays (vector), queues (queue), stacks (stack), heaps (priority_queue), linked lists ...
Read more >
stl_container
STL is a C++ library of container classes, algorithms, and iterators; ... array does not support element insertion or removal, vector supports fast...
Read more >
Containers in C++ STL (Standard Template Library)
A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found