| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #pragma once | 
| 2 |  |  |  |  |  |  | #include "string.h" | 
| 3 |  |  |  |  |  |  | #include "string_view.h" | 
| 4 |  |  |  |  |  |  | #include | 
| 5 |  |  |  |  |  |  | #include | 
| 6 |  |  |  |  |  |  | #include | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | /* | 
| 9 |  |  |  |  |  |  | * panda::unordered_string_set and panda::unordered_string_multiset are wrappers around STL's versions in case if keys are panda::string. | 
| 10 |  |  |  |  |  |  | * The goal is to make it possible to call some STL's methods with string_view | 
| 11 |  |  |  |  |  |  | */ | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | namespace panda { | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | template , class KeyEqual = std::equal_to, class Allocator = std::allocator> | 
| 16 | 16 |  |  |  |  |  | class unordered_string_set : public std::unordered_set { | 
| 17 |  |  |  |  |  |  | private: | 
| 18 |  |  |  |  |  |  | template | 
| 19 |  |  |  |  |  |  | static inline std::true_type  _is_base_string (panda::basic_string const volatile) { return std::true_type(); } | 
| 20 |  |  |  |  |  |  | static inline std::false_type _is_base_string (...) { return std::false_type(); } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | static_assert(decltype(_is_base_string(Key()))::value, "Key must be based on panda::basic_string"); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | using Base  = std::unordered_set; | 
| 25 |  |  |  |  |  |  | using SVKey = basic_string_view; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 14 |  |  |  |  |  | static Key _key_from_sv (const SVKey& key) { | 
| 28 |  |  |  |  |  |  | typedef typename Key::value_type FakeCharLiteral[1]; | 
| 29 | 14 |  |  |  |  |  | Key tmp(*(const FakeCharLiteral*)key.data()); | 
| 30 | 14 |  |  |  |  |  | tmp.length(key.length()); | 
| 31 | 14 |  |  |  |  |  | return tmp; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | public: | 
| 34 |  |  |  |  |  |  | using typename Base::key_type; | 
| 35 |  |  |  |  |  |  | using typename Base::value_type; | 
| 36 |  |  |  |  |  |  | using typename Base::size_type; | 
| 37 |  |  |  |  |  |  | using typename Base::difference_type; | 
| 38 |  |  |  |  |  |  | using typename Base::hasher; | 
| 39 |  |  |  |  |  |  | using typename Base::key_equal; | 
| 40 |  |  |  |  |  |  | using typename Base::allocator_type; | 
| 41 |  |  |  |  |  |  | using typename Base::reference; | 
| 42 |  |  |  |  |  |  | using typename Base::const_reference; | 
| 43 |  |  |  |  |  |  | using typename Base::pointer; | 
| 44 |  |  |  |  |  |  | using typename Base::const_pointer; | 
| 45 |  |  |  |  |  |  | using typename Base::iterator; | 
| 46 |  |  |  |  |  |  | using typename Base::const_iterator; | 
| 47 |  |  |  |  |  |  | using typename Base::local_iterator; | 
| 48 |  |  |  |  |  |  | using typename Base::const_local_iterator; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | using Base::Base; | 
| 51 |  |  |  |  |  |  | using Base::find; | 
| 52 |  |  |  |  |  |  | using Base::count; | 
| 53 |  |  |  |  |  |  | using Base::erase; | 
| 54 |  |  |  |  |  |  | using Base::equal_range; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | template ::value>::type> | 
| 57 | 5 | 50 |  |  |  |  | iterator find (X key) { return find(_key_from_sv(key)); } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | template ::value>::type> | 
| 60 |  |  |  |  |  |  | const_iterator find (X key) const { return find(_key_from_sv(key)); } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | template ::value>::type> | 
| 63 | 3 | 50 |  |  |  |  | size_type count (X key) const { return count(_key_from_sv(key)); } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | template ::value>::type> | 
| 66 | 3 | 50 |  |  |  |  | size_type erase (X key) { return erase(_key_from_sv(key)); } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | template ::value>::type> | 
| 69 | 3 | 50 |  |  |  |  | std::pair equal_range (X key) { return equal_range(_key_from_sv(key)); } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | template ::value>::type> | 
| 72 |  |  |  |  |  |  | std::pair equal_range (X key) const { return equal_range(_key_from_sv(key)); } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | }; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | template , class KeyEqual = std::equal_to, class Allocator = std::allocator> | 
| 77 | 16 |  |  |  |  |  | class unordered_string_multiset : public std::unordered_multiset { | 
| 78 |  |  |  |  |  |  | private: | 
| 79 |  |  |  |  |  |  | template | 
| 80 |  |  |  |  |  |  | static inline std::true_type  _is_base_string (panda::basic_string const volatile) { return std::true_type(); } | 
| 81 |  |  |  |  |  |  | static inline std::false_type _is_base_string (...) { return std::false_type(); } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | static_assert(decltype(_is_base_string(Key()))::value, "Key must be based on panda::basic_string"); | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | using Base  = std::unordered_multiset; | 
| 86 |  |  |  |  |  |  | using SVKey = basic_string_view; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 14 |  |  |  |  |  | static Key _key_from_sv (const SVKey& key) { | 
| 89 |  |  |  |  |  |  | typedef typename Key::value_type FakeCharLiteral[1]; | 
| 90 | 14 |  |  |  |  |  | Key tmp(*(const FakeCharLiteral*)key.data()); | 
| 91 | 14 |  |  |  |  |  | tmp.length(key.length()); | 
| 92 | 14 |  |  |  |  |  | return tmp; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  | public: | 
| 95 |  |  |  |  |  |  | using typename Base::key_type; | 
| 96 |  |  |  |  |  |  | using typename Base::value_type; | 
| 97 |  |  |  |  |  |  | using typename Base::size_type; | 
| 98 |  |  |  |  |  |  | using typename Base::difference_type; | 
| 99 |  |  |  |  |  |  | using typename Base::hasher; | 
| 100 |  |  |  |  |  |  | using typename Base::key_equal; | 
| 101 |  |  |  |  |  |  | using typename Base::allocator_type; | 
| 102 |  |  |  |  |  |  | using typename Base::reference; | 
| 103 |  |  |  |  |  |  | using typename Base::const_reference; | 
| 104 |  |  |  |  |  |  | using typename Base::pointer; | 
| 105 |  |  |  |  |  |  | using typename Base::const_pointer; | 
| 106 |  |  |  |  |  |  | using typename Base::iterator; | 
| 107 |  |  |  |  |  |  | using typename Base::const_iterator; | 
| 108 |  |  |  |  |  |  | using typename Base::local_iterator; | 
| 109 |  |  |  |  |  |  | using typename Base::const_local_iterator; | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | using Base::Base; | 
| 112 |  |  |  |  |  |  | using Base::find; | 
| 113 |  |  |  |  |  |  | using Base::count; | 
| 114 |  |  |  |  |  |  | using Base::erase; | 
| 115 |  |  |  |  |  |  | using Base::equal_range; | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | template ::value>::type> | 
| 118 | 5 | 50 |  |  |  |  | iterator find (X key) { return find(_key_from_sv(key)); } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | template ::value>::type> | 
| 121 |  |  |  |  |  |  | const_iterator find (X key) const { return find(_key_from_sv(key)); } | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | template ::value>::type> | 
| 124 | 3 | 50 |  |  |  |  | size_type count (X key) const { return count(_key_from_sv(key)); } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | template ::value>::type> | 
| 127 | 3 | 50 |  |  |  |  | size_type erase (X key) { return erase(_key_from_sv(key)); } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | template ::value>::type> | 
| 130 | 3 | 50 |  |  |  |  | std::pair equal_range (X key) { return equal_range(_key_from_sv(key)); } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | template ::value>::type> | 
| 133 |  |  |  |  |  |  | std::pair equal_range (X key) const { return equal_range(_key_from_sv(key)); } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | }; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | } |