[英]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
你的vector
来std::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.