1321369Sdim//===- StringSet.h - The LLVM Compiler Driver -------------------*- C++ -*-===//
2193323Sed//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6193323Sed//
7193323Sed//===----------------------------------------------------------------------===//
8193323Sed//
9193323Sed//  StringSet - A set-like wrapper for the StringMap.
10193323Sed//
11193323Sed//===----------------------------------------------------------------------===//
12193323Sed
13193323Sed#ifndef LLVM_ADT_STRINGSET_H
14193323Sed#define LLVM_ADT_STRINGSET_H
15193323Sed
16193323Sed#include "llvm/ADT/StringMap.h"
17321369Sdim#include "llvm/ADT/StringRef.h"
18321369Sdim#include "llvm/Support/Allocator.h"
19321369Sdim#include <cassert>
20321369Sdim#include <initializer_list>
21321369Sdim#include <utility>
22193323Sed
23193323Sednamespace llvm {
24193323Sed
25249423Sdim  /// StringSet - A wrapper for StringMap that provides set-like functionality.
26321369Sdim  template <class AllocatorTy = MallocAllocator>
27360784Sdim  class StringSet : public StringMap<NoneType, AllocatorTy> {
28360784Sdim    using base = StringMap<NoneType, AllocatorTy>;
29321369Sdim
30193323Sed  public:
31296417Sdim    StringSet() = default;
32296417Sdim    StringSet(std::initializer_list<StringRef> S) {
33296417Sdim      for (StringRef X : S)
34296417Sdim        insert(X);
35296417Sdim    }
36353358Sdim    explicit StringSet(AllocatorTy A) : base(A) {}
37249423Sdim
38280031Sdim    std::pair<typename base::iterator, bool> insert(StringRef Key) {
39249423Sdim      assert(!Key.empty());
40360784Sdim      return base::insert(std::make_pair(Key, None));
41193323Sed    }
42309124Sdim
43309124Sdim    template <typename InputIt>
44309124Sdim    void insert(const InputIt &Begin, const InputIt &End) {
45309124Sdim      for (auto It = Begin; It != End; ++It)
46360784Sdim        base::insert(std::make_pair(*It, None));
47309124Sdim    }
48353358Sdim
49353358Sdim    template <typename ValueTy>
50353358Sdim    std::pair<typename base::iterator, bool>
51353358Sdim    insert(const StringMapEntry<ValueTy> &MapEntry) {
52353358Sdim      return insert(MapEntry.getKey());
53353358Sdim    }
54193323Sed  };
55193323Sed
56321369Sdim} // end namespace llvm
57321369Sdim
58193323Sed#endif // LLVM_ADT_STRINGSET_H
59