summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-0/vref.hpp
blob: 7fe20455d5daf0ed21a22fb6dab1be5eaee05f50 (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
#pragma once

#include "common.hpp"
#include "memorystore.hpp"
#include "ref.hpp"
#include "value.hpp"

namespace intellect {
namespace level0 {

template <typename T>
struct vref
{
	vref(value<T> *p) : ptr(p) { }
	value<T>* operator->() { return ptr; }
	operator T const &() const { return *ptr; }

	vref(T const & val) : ptr(alloc(new value<T>(val))) { }

	vref(ref const & other) : ptr(static_cast<value<T>*>(other.ptr)) { }
	operator ref() { return ptr; }

	// for use by containers
	bool operator<(vref<T> const & other) const { return self.ptr < other.ptr; }

	value<T> * const ptr;
};


}
}