blob: f21952af09681e5d008e4f0b30cce39f6cb9ddf9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "concept.hpp"
// Makes string values interchangeable with the concepts
// they name.
template<>
struct value<std::string> : public concept, public std::string
{
//using std::string::basic_string;
value(std::string);
value(cid);
operator cid();
static value& of(cid c)
{
return *static_cast<value*>(c);
}
};
using str = value<std::string>;
cid operator"" _c(const char* str, std::size_t len)
{
return value<std::string>({str,len});
}
#include <unordered_map>
concept namesByConcept;
std::unordered_map<value<std::string>,concept,std::hash<std::string>> conceptsByName;
value<std::string>::value(std::string s)
: std::string(s)
{ }
value<std::string>::value(cid c)
: std::string(of(namesByConcept.get(c)))
{ }
value<std::string>::operator cid()
{
try {
return &conceptsByName.at(*this);
} catch (std::out_of_range) {
auto insertion = conceptsByName.emplace(*this, concept());
cid con = &insertion.first->second;
cid nam = const_cast<cid>((const cid)&insertion.first->first);
namesByConcept.link(con, nam);
return con;
}
}
|