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
23namespace 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> {
28 using base = 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
37 std::pair<typename base::iterator, bool> insert(StringRef Key) {
38 assert(!Key.empty());
39 return base::insert(std::make_pair(Key, '\0'));
40 }
41
42 template <typename InputIt>
43 void insert(const InputIt &Begin, const InputIt &End) {
44 for (auto It = Begin; It != End; ++It)
45 base::insert(std::make_pair(*It, '\0'));
46 }
47 };
48
49} // end namespace llvm
50
51#endif // LLVM_ADT_STRINGSET_H
52