1 //===- StringSet.h - The LLVM Compiler Driver -------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // StringSet - A set-like wrapper for the StringMap.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ADT_STRINGSET_H
14 #define LLVM_ADT_STRINGSET_H
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Allocator.h"
20 #include <initializer_list>
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
>;
31 StringSet() = default;
32 StringSet(std::initializer_list
<StringRef
> S
) {
36 explicit StringSet(AllocatorTy A
) : base(A
) {}
38 std::pair
<typename
base::iterator
, bool> insert(StringRef Key
) {
40 return base::insert(std::make_pair(Key
, '\0'));
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'));
49 template <typename ValueTy
>
50 std::pair
<typename
base::iterator
, bool>
51 insert(const StringMapEntry
<ValueTy
> &MapEntry
) {
52 return insert(MapEntry
.getKey());
56 } // end namespace llvm
58 #endif // LLVM_ADT_STRINGSET_H