먼저 contains_t라는 새 함수 객체의 정의가옵니다. 은 도우미 클래스 std :: unary_function ( 의 올바른 typedef 생성을 용이하게하기 위해 C++ 표준 라이브러리의 부분)에서 상속 받았을 수 있으며 인수 및 결과 유형이 으로 자동 정의되었지만이를 명확하게하기 위해, 필수 typedef는 명시 적으로 입니다. 인수 유형이 const boost :: any &에서 boost :: any로 변경되어 잠재적 인 참조가 참조되는 것을 방지합니다. 이는 잘못된 것입니다. 구현은 이전처럼 일 뿐이며 여기서는 함수 호출 연산자에 배치됩니다.참조를 참조하지 못하도록`(const boost :: any & a)`대신`(boost :: any a)`를 사용하십시오.
template <typename T> struct contains_t {
typedef boost::any argument_type;
typedef bool result_type;
bool operator()(boost::any a) const {
return typeid(T)==a.type();
}
};
다음 구현은 레퍼런스에 대한 참조를받을 수있는 잠재력을 가지고 왜?
template <typename T> struct contains_t {
typedef boost::any argument_type;
typedef bool result_type;
bool operator()(const boost::any& a) const {
return typeid(T)==a.type();
}
};
부스트 때문에 당신
블록 견적은 무엇입니까? –
http://www.amazon.com/Beyond-Standard-Library-Introduction-Boost/dp/0321133544 – q0987