简体   繁体   English

如何使用boost :: algorithm :: join与对象的std :: vector?

[英]How to use boost::algorithm::join with std::vector of objects?

I understand the use of boost::algorithm::join on a vector of std::string but how do I use it for an std::vector<std::unique_ptr<Foo>> ? 我了解在std::string的向量上使用boost::algorithm::join ,但是如何将其用于std::vector<std::unique_ptr<Foo>>

I guess I'm looking for some kind of apply function that I can pass in a lambda so I can transform the std::unique_ptr to std::string. 我想我正在寻找某种我可以在lambda中传递的apply函数,以便可以将std :: unique_ptr转换为std :: string。

Looking are the source code of join , it seems there's no way to do that. 看一下join源代码 ,似乎没有办法。 The return value must be of range_value<SequenceSequenceT>::type type which maps to std::unique_ptr<Foo> in your case. 返回值必须是range_value<SequenceSequenceT>::type类型,在您的情况下,该类型映射到std::unique_ptr<Foo> You can std::transform your vector to std::vector<std::string> , which is a bit of a waste. 你可以std::transform你的vectorstd::vector<std::string>这是一个有点浪费。 Alternatively you could implement your own version of join that applies the transformation itself as it goes. 或者,您可以实现自己的连接版本,该版本将在转换过程中应用转换本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过boost :: algorithm :: join和boost :: adaptors :: transformed转换boost.asio :: ip :: address的std :: vector - Transform a std::vector of boost.asio::ip::address via boost::algorithm::join and boost::adaptors::transformed 如何在元组上使用boost :: algorithm :: join? - how to use boost::algorithm::join on tuples? 具有boost :: thread封装的insde的对象的std :: vector - std::vector of objects with a boost::thread encapsulated insde 如何在布尔元素向量上使用 std::find 算法 - How to use std::find algorithm on a vector of boolean elements 将字符串向量加入std :: ostream(如boost :: join) - Join vector of strings to std::ostream (like boost::join) boost :: algorithm ::包含std :: vector <long> 和长期价值 - boost::algorithm::contains std::vector<long> & long value 如何使用boost lambda来填充带有新对象的指针向量 - How to use boost lambda to populate a vector of pointers with new objects 如何使用boost :: spirit :: qi与std :: vector <token_type> 而不是std :: string - How to use boost::spirit::qi with a std::vector<token_type> instead of std::string 如何对 std::vector 元素中的对象使用 shared_mutex - How to use shared_mutex for objects in std::vector elements 有没有办法在 boost::asio 中使用 std::iostream 对象? - Is there a way to use std::iostream objects with boost::asio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM