SFINAE 模板错误
SFINAE Template Error
我正在使用 SFINEA 订阅 ROS 中的通用主题,它会收听每个主题,并使用 SFINEA return header.stamp
时间(如果存在)。这可以更快地反序列化。唯一的问题是我在设置订户时遇到问题。我不断收到以下编译错误:
CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o:
In function PerformanceTracker::topicCallback(boost::shared_ptr<topic_tools::ShapeShifter>)
ros/src/performance_tracker/src/performance_tracker.cpp:32:
undefined reference to boost::disable_if<timewarp::has_header<boost::shared_ptr<topic_tools::ShapeShifter> >, ros::Time>::type
timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter> >(boost::shared_ptr<topic_tools::ShapeShifter>)
主要
// Subscribe To Generic Message
_sub = _nh.subscribe( _topicName, 1, &PerformanceTracker::topicCallback, this);
void PerformanceTracker::topicCallback(const boost::shared_ptr<topic_tools::ShapeShifter> data){
//Current Time
ros::Time begin = ros::Time::now();
ros::Time timePublished = timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter>>(data);
}
命名空间CLASS
namespace timewarp
{
template <typename T>
struct has_header {
typedef char yes[1];
typedef char no[2];
template <typename C>
static yes& test(typename C::_header_type*);
template <typename>
static no& test(...);
// If the "sizeof" the result of calling test<T>(0) would be equal to the sizeof(yes),
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter> data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter>);
}
您正在将 boost::shared_ptr<topic_tools::ShapeShifter>
类型作为 MsgType 传递给 has_header<T>
而不是 topic_tools::ShapeShifter
。
我相信你想做的事情:
ros::Time timePublished = timewarp::extractTime<topic_tools::ShapeShifter>(data);
并在使用时使用 const refs 参数 :)
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>& data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>&)
{
return ros::Time::now();
// or whatever ros time you need to return for types without headers
}
}
我正在使用 SFINEA 订阅 ROS 中的通用主题,它会收听每个主题,并使用 SFINEA return header.stamp
时间(如果存在)。这可以更快地反序列化。唯一的问题是我在设置订户时遇到问题。我不断收到以下编译错误:
CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o:
In function PerformanceTracker::topicCallback(boost::shared_ptr<topic_tools::ShapeShifter>)
ros/src/performance_tracker/src/performance_tracker.cpp:32:
undefined reference to boost::disable_if<timewarp::has_header<boost::shared_ptr<topic_tools::ShapeShifter> >, ros::Time>::type
timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter> >(boost::shared_ptr<topic_tools::ShapeShifter>)
主要
// Subscribe To Generic Message
_sub = _nh.subscribe( _topicName, 1, &PerformanceTracker::topicCallback, this);
void PerformanceTracker::topicCallback(const boost::shared_ptr<topic_tools::ShapeShifter> data){
//Current Time
ros::Time begin = ros::Time::now();
ros::Time timePublished = timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter>>(data);
}
命名空间CLASS
namespace timewarp
{
template <typename T>
struct has_header {
typedef char yes[1];
typedef char no[2];
template <typename C>
static yes& test(typename C::_header_type*);
template <typename>
static no& test(...);
// If the "sizeof" the result of calling test<T>(0) would be equal to the sizeof(yes),
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter> data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter>);
}
您正在将 boost::shared_ptr<topic_tools::ShapeShifter>
类型作为 MsgType 传递给 has_header<T>
而不是 topic_tools::ShapeShifter
。
我相信你想做的事情:
ros::Time timePublished = timewarp::extractTime<topic_tools::ShapeShifter>(data);
并在使用时使用 const refs 参数 :)
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>& data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>&)
{
return ros::Time::now();
// or whatever ros time you need to return for types without headers
}
}