Spicy
id.h
1 // Copyright (c) 2020-now by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <iostream>
6 #include <string>
7 
8 #include <hilti/ast/meta.h>
9 #include <hilti/base/id-base.h>
10 #include <hilti/base/util.h>
11 
12 namespace hilti {
13 
15 class ID : public detail::IDBase<ID> {
16 public:
17  using Base = detail::IDBase<ID>;
18 
20  ID() {}
21 
23  ID(const char* s) : Base(s) {}
24  explicit ID(std::string_view s) : Base(s) {}
25 
31  ID(std::string_view s, AlreadyNormalized n) : Base(s, n) {}
32 
34  template<typename... T, typename enable = std::enable_if_t<(... && std::is_convertible_v<T, std::string_view>)>>
35  explicit ID(const T&... s) : Base(s...) {}
36 
38  ID(std::initializer_list<std::string_view> x) : Base(x) {}
39 
40  ID(const Base& other) : Base(other) {}
41 
42  ID(Base&& other) noexcept : Base(other) {}
43 };
44 
45 inline std::ostream& operator<<(std::ostream& out, const ID& id) {
46  out << std::string(id);
47  return out;
48 }
49 
50 } // namespace hilti
51 
52 namespace std {
53 template<>
55  std::size_t operator()(const hilti::ID& id) const { return hash<std::string>()(id); }
56 };
57 } // namespace std
Definition: id.h:15
ID(const char *s)
Definition: id.h:23
ID(std::initializer_list< std::string_view > x)
Definition: id.h:38
ID(std::string_view s, AlreadyNormalized n)
Definition: id.h:31
ID()
Definition: id.h:20
ID(const T &... s)
Definition: id.h:35
Definition: id-base.h:28
Definition: id.h:54