c++ - 如何将 boost::Makevariantover 转换为 vector

标签 c++ boost apply-visitor

我有一个 boost::makevariantover。我怎样才能将其转换为 vector 。任何示例都将有助于使用 boost::apply_visitor

class pixel_visitor
    : public boost::static_visitor<>
{

public:

template <typename T>
    void operator() (const ome::compat::shared_ptr<PixelBuffer<T> >& v)
    {
      std::cout << std::real(v);
    }    
};

pixelBuffer test= buf.vbuffer();    
test.apply_visitor(&pixel_visitor());

在哪里

typedef boost::make_variant_over<pixel_buffer_types>::type     pixelBuffer;

最佳答案

代替 .vbuffer() 调用 .array(),它已经 applies the/a visitor "for you" :

template<typename T>
inline typename PixelBuffer<T>::array_ref_type&
VariantPixelBuffer::array()
{
  detail::VariantPixelBufferVisitor<T> v;
  return boost::apply_visitor(v, buffer).array();
}

或原始类型的 .data()。

关于c++ - 如何将 boost::Makevariantover 转换为 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36494175/

相关文章:

c++ - 接收错误 "no matching function for call to ' getline(std::istream&, int&, char )'"

c++ - 此功能的最佳位置在哪里? C++

c++ - 对 vtable SFML Android 的 undefined reference

python - c++0x std::shared_ptr 与 boost::shared_ptr

c++ - 如何让 apply-visitor 不丢弃 const 限定符?

c# - 如果我的程序正在将 dll 文件复制到临时目录,我是否需要特定权限?

c++ - 使用 Boost C++ 的多线程 - 同步问题

c++ - 创建boost::shared_ptr的深层拷贝

C++ boost::variant 泛型转换器

c++ - boost :将变体与 apply_visitor 进行比较