1 | //===- StringSet.h - The LLVM Compiler Driver -------------------*- C++ -*-===// |
2 | // |
3 | // The LLVM Compiler Infrastructure |
4 | // |
5 | // This file is distributed under the University of Illinois Open |
6 | // Source License. See LICENSE.TXT for details. |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | // |
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/StringMap.h" |
18 | #include "llvm/ADT/StringRef.h" |
19 | #include "llvm/Support/Allocator.h" |
20 | #include <cassert> |
21 | #include <initializer_list> |
22 | #include <utility> |
23 | |
24 | namespace llvm { |
25 | |
26 | /// StringSet - A wrapper for StringMap that provides set-like functionality. |
27 | template <class AllocatorTy = MallocAllocator> |
28 | class StringSet : public StringMap<char, AllocatorTy> { |
29 | using base = StringMap<char, AllocatorTy>; |
30 | |
31 | public: |
32 | StringSet() = default; |
33 | StringSet(std::initializer_list<StringRef> S) { |
34 | for (StringRef X : S) |
35 | insert(X); |
36 | } |
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 | |
50 | } // end namespace llvm |
51 | |
52 | #endif // LLVM_ADT_STRINGSET_H |
53 | |