diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-21 13:37:18 -0500 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-21 13:37:18 -0500 |
commit | 6e81ffa9f5baabe8d4b16fa927ce423fbe26771e (patch) | |
tree | 3abbf34ccf1cb05d26f4a83a8dcf3455aebe1c90 /starts/meaning-vm/helpers.hpp | |
parent | 302fc80f638783d17cd3b496284a535044241297 (diff) | |
download | standingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.tar.gz standingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.zip |
direct cast concept from string
Diffstat (limited to 'starts/meaning-vm/helpers.hpp')
-rw-r--r-- | starts/meaning-vm/helpers.hpp | 50 |
1 files changed, 2 insertions, 48 deletions
diff --git a/starts/meaning-vm/helpers.hpp b/starts/meaning-vm/helpers.hpp index f21952a..6659019 100644 --- a/starts/meaning-vm/helpers.hpp +++ b/starts/meaning-vm/helpers.hpp @@ -1,49 +1,3 @@ -#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> +#pragma once -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; - } -} +#include "concept.hpp" |