9 #ifndef __NODAMUSHI_REGISTERORCLUSTER_HPP__ 10 #define __NODAMUSHI_REGISTERORCLUSTER_HPP__ 13 # include <functional> 26 using deleter = std::function<void(
void*)>;
35 reg(true),p(r,[](void *v){
delete static_cast<reg_t*>(v);}){}
37 reg(false),p(c,[](void *v){
delete static_cast<clu_t*>(v);}){}
53 throw std::runtime_error(
"bad cast.not a register");
57 throw std::runtime_error(
"register is empty");
59 reg_t* r = static_cast<reg_t*>(d);
68 throw std::runtime_error(
"bad cast.not a cluster");
72 throw std::runtime_error(
"cluster is empty");
74 clu_t* r = static_cast<clu_t*>(d);
83 throw std::runtime_error(
"bad cast.not a register");
87 throw std::runtime_error(
"register is empty");
89 reg_t* r = static_cast<reg_t*>(d);
98 throw std::runtime_error(
"bad cast.not a cluster");
102 throw std::runtime_error(
"cluster is empty");
104 clu_t* r = static_cast<clu_t*>(d);
108 const void*
get(){
return p.get();}
111 std::unique_ptr<void, deleter> p;
119 static constexpr
bool is_register =
true;
120 template<
typename R,
typename C>
121 static constexpr
const R&
select(
const R& r,
const C& c){
return r;}
122 template<
typename R,
typename C>
123 static constexpr R&
select(R& r,C& c){
return r;}
124 template<
typename R,
typename C>
129 template<
typename R,
typename C>
139 static constexpr
bool is_register =
false;
140 template<
typename R,
typename C>
141 static constexpr
const C&
select(
const R& r,
const C& c){
return c;}
142 template<
typename R,
typename C>
143 static constexpr C&
select(R& r,C& c){
return c;}
145 template<
typename R,
typename C>
150 template<
typename R,
typename C>
161 #endif // __NODAMUSHI_REGISTERORCLUSTER_HPP__ static constexpr R & select(R &r, C &c)
static C * get(reg_or_cluster< R, C > &rc)
static constexpr C & select(R &r, C &c)
const clu_t & get_cluster() const
unique_ptr<Register> or unique_ptr<Cluster>
reg_or_cluster & operator=(const reg_or_cluster &)=delete
static R * get(reg_or_cluster< R, C > &rc)
static constexpr const R & select(const R &r, const C &c)
std::function< void(void *)> deleter
static const R * get(const reg_or_cluster< R, C > &rc)
const reg_t & get_register() const
static constexpr const C & select(const R &r, const C &c)
reg_or_cluster(const reg_or_cluster &)=delete
bool is_register() const noexcept
static const C * get(const reg_or_cluster< R, C > &rc)
bool is_cluster() const noexcept