给定其成员值引用的std :: tuple对象

时间:2018-11-06 07:27:39

标签: c++ language-lawyer template-meta-programming void-pointers stdtuple

假设我有一个std :: tuple:

std::tuple< int, float, bool > my_tuple;

和一个功能

void my_function( int& i, float& f, bool& b);

如果我可以保证其参数my_tuplemy_function的成员,是否可以从i, f, b中检索my_tuple对象?

例如-合法:

void my_function( int& i, float& f, bool& b){
  using tuple_type = std::tupl< int, float, bool >;
  tuple_type& my_tuple = *reinterpret_cast<tuple_type*>(reinterpret_cast<void*>(&i))
  // do stuff with my_tuple, like call its copy constructor, etc
}

0 个答案:

没有答案