1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi"). 7 #include <initializer_list> 9 #include <unordered_set> 16 initializer_list, move, unordered_set
21 :
public unordered_set<Key>
23 using Base = unordered_set<Key>;
37 Base( &a_key, &a_key + 1 )
41 template<
class Integer >
43 Base( range.begin(), range.end() )
46 Set_( tag::Values, initializer_list<Key> values ):
47 Base( move( values ) )
50 template<
class Input_iterator >
51 Set_( tag::Iterators,
const Input_iterator first,
const Input_iterator beyond ):
56 template<
class Key,
class Arg >
57 auto is_in(
const unordered_set<Key>& set,
const Arg& v )
59 {
return set.count( v ) > 0; }
65 inline auto as_set(
const Key& a_key )
69 template<
class Integer >
75 inline auto as_set(
const initializer_list<Key>& values )
77 {
return { values }; }
83 auto set_union(
const unordered_set<Key>& a,
const unordered_set<Key>& b )
86 const unordered_set<Key>& smallest = (a.size() < b.size()? a : b);
87 const unordered_set<Key>& largest = (a.size() < b.size()? b : a);
90 for(
const Key& key : smallest )
97 template<
class Key,
class Arg >
98 auto set_union(
const unordered_set<Key>& a,
const Arg& b )
102 template<
class Key,
class Arg >
103 auto set_union(
const Arg& a,
const unordered_set<Key>& b )
107 template<
class Key >
112 for(
const Key& key : b )
119 template<
class Key,
class Arg >
124 template<
class Key >
128 const unordered_set<Key>& smallest = (a.size() < b.size()? a : b);
129 const unordered_set<Key>& largest = (a.size() < b.size()? b : a);
132 for(
const Key& key : smallest )
134 if(
is_in( largest, key ) )
136 result.insert( key );
145 template<
class Key >
149 for(
const Key& key : b )
Set_(tag::Values, initializer_list< Key > values)
Set_(tag::Iterators, const Input_iterator first, const Input_iterator beyond)
auto set_difference(const unordered_set< Key > &a, const unordered_set< Key > &b) -> Set_< Key >
A drop-in replacement for bool without implicit conversion from/to types other than bool.
auto as_set(const Key &a_key) -> Set_< Key >
auto is_in(const basic_string_view< Char > &sv, const Char ch) noexcept -> Truth
Set_(const Range_< Integer > range)
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
$define_tag(NAME) defines NAME as a ~unique pointer type in namespace tag.
auto set_intersection(const unordered_set< Key > &a, const unordered_set< Key > &b) -> Set_< Key >
CPPX_DEFINE_TAG(Iterators)
auto set_union(const unordered_set< Key > &a, const unordered_set< Key > &b) -> Set_< Key >