Support "in" operator for STL containers
See original GitHub issueThis 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:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.