aboutsummaryrefslogtreecommitdiff
path: root/src/utility.h
blob: db33608d1a4b880e9e6fb1c56355d6edf05cd121 (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
#ifndef TRIE_SRC_UTILITY_H_
#define TRIE_SRC_UTILITY_H_

namespace detail {

template <
	typename Type
>
class optional_ptr {
	public:
		typedef typename std::add_pointer<Type>::type pointer;
		typedef Type element_type;

		optional_ptr():
			value_(false, nullptr) { }

		optional_ptr(pointer ptr):
			value_(true, ptr) { }

		inline operator bool() const {
			return this->value_.first;
		}

		inline pointer get() const {
			return this->value_.second;
		}

	private:
		const std::pair<bool, pointer> value_;

};

}

#endif  // TRIE_SRC_UTILITY_H_