mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::set`, `std::unordered_set` and `std::multiset` when used from Swift code. As of now, `CxxSet` adds a `contains` function to C++ sets. C++ stdlib set types are automatically conformed to `CxxSet`: `std::set`, `unordered_set`, `std::multiset`. Custom user types are not conformed to `CxxSet` automatically: while a custom type might have an interface similar to `std::set`, the semantics might differ, and adding a conformance would cause confusion.
16 lines
517 B
C++
16 lines
517 B
C++
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
|
|
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
|
|
|
|
#include <set>
|
|
#include <unordered_set>
|
|
|
|
using SetOfCInt = std::set<int>;
|
|
using UnorderedSetOfCInt = std::unordered_set<int>;
|
|
using MultisetOfCInt = std::multiset<int>;
|
|
|
|
inline SetOfCInt initSetOfCInt() { return {1, 5, 3}; }
|
|
inline UnorderedSetOfCInt initUnorderedSetOfCInt() { return {2, 4, 6}; }
|
|
inline MultisetOfCInt initMultisetOfCInt() { return {2, 2, 4, 6}; }
|
|
|
|
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
|