emilib
string_interning.hpp
1 // By Emil Ernerfeldt 2014-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 // HISTORY:
7 // Created in 2014 for Ghostel
8 // Moved into emilib in 2016
9 
10 #pragma once
11 
12 #include <string>
13 #include <unordered_map>
14 
15 namespace emilib {
16 
24 {
25 public:
26  ~StringInterner();
27 
29  const char* intern(const std::string& str);
30 
31 private:
32  std::unordered_map<std::string, char*> _map;
33 };
34 
36 const char* intern_string(const std::string& str);
37 
38 } // namespace emilib
const char * intern(const std::string &str)
Not thread-safe. The allocated string will be freed when this StringInterner dies.
Definition: string_interning.hpp:23
Definition: coroutine.hpp:18