LLVM 24.0.0git
StringSet.h
Go to the documentation of this file.
1//===- StringSet.h - An efficient set built on StringMap --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// StringSet - A set-like wrapper for the StringMap.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ADT_STRINGSET_H
15#define LLVM_ADT_STRINGSET_H
16
17#include "llvm/ADT/ADL.h"
19#include "llvm/ADT/StringMap.h"
21
22namespace llvm {
23
24/// StringSet - A wrapper for StringMap that provides set-like functionality.
25template <class AllocatorTy = MallocAllocator>
27 : public StringMap<EmptyStringSetTag, AllocatorTy> {
29
30public:
31 StringSet() = default;
32 StringSet(std::initializer_list<StringRef> initializer) {
33 for (StringRef str : initializer)
34 insert(str);
35 }
36 template <typename Range> StringSet(llvm::from_range_t, Range &&R) {
37 insert(adl_begin(R), adl_end(R));
38 }
39 explicit StringSet(AllocatorTy a) : Base(a) {}
40
41 std::pair<typename Base::iterator, bool> insert(StringRef key) {
42 return Base::try_emplace(key);
43 }
44
45 template <typename InputIt>
46 void insert(InputIt begin, InputIt end) {
47 for (auto it = begin; it != end; ++it)
48 insert(*it);
49 }
50
51 template <typename Range> void insert_range(Range &&R) {
52 insert(adl_begin(R), adl_end(R));
53 }
54
55 template <typename ValueTy>
56 std::pair<typename Base::iterator, bool>
58 return insert(mapEntry.getKey());
59 }
60
61 /// Check if the set contains the given \c key.
62 [[nodiscard]] bool contains(StringRef key) const {
63 return Base::contains(key);
64 }
65};
66
67} // end namespace llvm
68
69#endif // LLVM_ADT_STRINGSET_H
This file defines the StringMap class.
#define LLVM_ATTRIBUTE_WARN_UNUSED
Definition Compiler.h:240
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains library features backported from future STL versions.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef getKey() const
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Definition StringMap.h:370
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
StringSet()=default
StringSet(AllocatorTy a)
Definition StringSet.h:39
StringSet(llvm::from_range_t, Range &&R)
Definition StringSet.h:36
std::pair< typename Base::iterator, bool > insert(const StringMapEntry< ValueTy > &mapEntry)
Definition StringSet.h:57
void insert(InputIt begin, InputIt end)
Definition StringSet.h:46
StringSet(std::initializer_list< StringRef > initializer)
Definition StringSet.h:32
bool contains(StringRef key) const
Check if the set contains the given key.
Definition StringSet.h:62
void insert_range(Range &&R)
Definition StringSet.h:51
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition StringSet.h:41
This is an optimization pass for GlobalISel generic memory operations.
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
Definition ADL.h:78
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
Definition ADL.h:86