LLVM  10.0.0svn
StringSet.h
Go to the documentation of this file.
1 //===- StringSet.h - The LLVM Compiler Driver -------------------*- 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 // StringSet - A set-like wrapper for the StringMap.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ADT_STRINGSET_H
14 #define LLVM_ADT_STRINGSET_H
15 
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Allocator.h"
19 #include <cassert>
20 #include <initializer_list>
21 #include <utility>
22 
23 namespace llvm {
24 
25  /// StringSet - A wrapper for StringMap that provides set-like functionality.
26  template <class AllocatorTy = MallocAllocator>
27  class StringSet : public StringMap<char, AllocatorTy> {
29 
30  public:
31  StringSet() = default;
32  StringSet(std::initializer_list<StringRef> S) {
33  for (StringRef X : S)
34  insert(X);
35  }
36  explicit StringSet(AllocatorTy A) : base(A) {}
37 
38  std::pair<typename base::iterator, bool> insert(StringRef Key) {
39  assert(!Key.empty());
40  return base::insert(std::make_pair(Key, '\0'));
41  }
42 
43  template <typename InputIt>
44  void insert(const InputIt &Begin, const InputIt &End) {
45  for (auto It = Begin; It != End; ++It)
46  base::insert(std::make_pair(*It, '\0'));
47  }
48 
49  template <typename ValueTy>
50  std::pair<typename base::iterator, bool>
51  insert(const StringMapEntry<ValueTy> &MapEntry) {
52  return insert(MapEntry.getKey());
53  }
54  };
55 
56 } // end namespace llvm
57 
58 #endif // LLVM_ADT_STRINGSET_H
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:125
StringSet(AllocatorTy A)
Definition: StringSet.h:36
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
Key
PAL metadata keys.
StringSet(std::initializer_list< StringRef > S)
Definition: StringSet.h:32
StringRef getKey() const
Definition: StringMap.h:136
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
std::pair< typename base::iterator, bool > insert(const StringMapEntry< ValueTy > &MapEntry)
Definition: StringSet.h:51
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:370
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:219
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:27
StringSet()=default
void insert(const InputIt &Begin, const InputIt &End)
Definition: StringSet.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48