summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-2/baseref.hpp
blob: 644f4b8fd787237e0c95ac809d56d36a2dd5eea5 (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
#pragma once

#include "common.hpp"
#include "funcs.hpp"
#include "../level-1/baseref.hpp"

#include <functional>

namespace intellect {
namespace level2 {

template <typename ref>
struct baseref : public level1::baseref<ref>
{
	using level1::template baseref<ref>::baseref;

	// thread-local context
	static ref & context() { return level2::context(); }

	template <typename... Refs>
	ref operator()(ref first, Refs... rest) { return level2::dohabit(self, {first, rest...}); }
	ref operator()(std::initializer_list<std::initializer_list<ref>> pairs) { return level2::dohabit(self, pairs); }
	ref operator()() { return level2::dohabit(self); }

	template <typename... Refs>
	ref act(ref habit, Refs... rest) { return level2::dohabit(habit, {self, rest...}); }

	void replace(ref other) { *self.ptr() = *other.ptr(); }
};

}
}