LLVM 22.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"
20
21namespace llvm {
22
23/// StringSet - A wrapper for StringMap that provides set-like functionality.
24template <class AllocatorTy = MallocAllocator>
25class StringSet : public StringMap<std::nullopt_t, AllocatorTy> {
27
28public:
29 StringSet() = default;
30 StringSet(std::initializer_list<StringRef> initializer) {
31 for (StringRef str : initializer)
32 insert(str);
33 }
34 template <typename Range> StringSet(llvm::from_range_t, Range &&R) {
35 insert(adl_begin(R), adl_end(R));
36 }
37 explicit StringSet(AllocatorTy a) : Base(a) {}
38
39 std::pair<typename Base::iterator, bool> insert(StringRef key) {
40 return Base::try_emplace(key);
41 }
42
43 template <typename InputIt>
44 void insert(InputIt begin, InputIt end) {
45 for (auto it = begin; it != end; ++it)
46 insert(*it);
47 }
48
49 template <typename Range> void insert_range(Range &&R) {
50 insert(adl_begin(R), adl_end(R));
51 }
52
53 template <typename ValueTy>
54 std::pair<typename Base::iterator, bool>
56 return insert(mapEntry.getKey());
57 }
58
59 /// Check if the set contains the given \c key.
60 bool contains(StringRef key) const { return Base::contains(key); }
61};
62
63} // end namespace llvm
64
65#endif // LLVM_ADT_STRINGSET_H
This file defines the StringMap class.
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
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
StringSet()=default
StringSet(AllocatorTy a)
Definition StringSet.h:37
StringSet(llvm::from_range_t, Range &&R)
Definition StringSet.h:34
std::pair< typename Base::iterator, bool > insert(const StringMapEntry< ValueTy > &mapEntry)
Definition StringSet.h:55
void insert(InputIt begin, InputIt end)
Definition StringSet.h:44
StringSet(std::initializer_list< StringRef > initializer)
Definition StringSet.h:30
bool contains(StringRef key) const
Check if the set contains the given key.
Definition StringSet.h:60
void insert_range(Range &&R)
Definition StringSet.h:49
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition StringSet.h:39
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