diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-30 11:24:17 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-30 11:24:17 -0800 |
commit | 0965367d7581534f5d84cc93a66d3a38a5d646fe (patch) | |
tree | 73aaf73b53836a05dae93a430bed36a9ccf5322a /starts/meaning-vm/level-1/funcs.cpp | |
parent | 3fdf216140d3b23d016d55b69cf439fed4c174a0 (diff) | |
download | standingwithresilience-0965367d7581534f5d84cc93a66d3a38a5d646fe.tar.gz standingwithresilience-0965367d7581534f5d84cc93a66d3a38a5d646fe.zip |
fixed compilation errors; next is runtime
Diffstat (limited to 'starts/meaning-vm/level-1/funcs.cpp')
-rw-r--r-- | starts/meaning-vm/level-1/funcs.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp index 1e6bd9d..2ba2d0f 100644 --- a/starts/meaning-vm/level-1/funcs.cpp +++ b/starts/meaning-vm/level-1/funcs.cpp @@ -11,6 +11,26 @@ namespace level1 { using namespace concepts; +// for generalizing unique data references. not used yet, could replace conceptsByName, +// but note this doesn't use a type link, and conceptsByName does. +template <typename T> +ref conceptByData(T const& data, concept* con = nullptr, concept* allocator = nullptr) +{ + static std::map<T, ref> conceptsByData; // std::map works for typeid data + auto res = conceptsByData.find(data); + if (res != conceptsByData.end()) { + if (con != nullptr) { throw std::logic_error("unique data concept already specified"); } + return res->second; + } else { + if (con == nullptr) { + if (allocator == nullptr) { allocator = level0::concepts::allocations(); } + con = level0::alloc(allocator); + } + conceptsByData.emplace(data, con); + return con; + } +} + // ensure name link and backing structure are created prior to first use static auto & namestruct() { |