개체에 대한 참조를 boost::any
개체에 저장하려고합니다. boost :: any 객체를 어떻게 초기화합니까? std::ref()
을 시도했지만 boost::any
은 std::reference_wrapper<>
으로 초기화됩니다. 예를 들어, 나는 boost::any
대신 int&
를 포함 할어떻게 개체에 대한 참조와 함께 boost :: any를 초기화합니까?
#include <boost/any.hpp>
#include <cxxabi.h>
#include <iostream>
int main(void)
{
int s;
int i = 0;
boost::any x(std::ref(i));
std::cout << abi::__cxa_demangle(x.type().name(), 0, 0, &s) << "\n";
return 0;
}
인쇄
std::reference_wrapper<int>
다음.
참조 유형에 대한 type_info가없는 대신 참조되는 유형에 대한 type_info는'cout << typeid (int) .name() << >> \ t "<< typeid (int &)입니다. << "\ t"<< typeid (int) == typeid (int &)'는'ii 1'을 생성하므로 any가 참조를 저장하더라도 그 타입은 여전히'typeid (int)'가됩니다. – stellarpower