【发布时间】:2015-09-01 10:29:16
【问题描述】:
我需要在单个char 值上调用boost::trim_left_if:
// pseudo code; not tested.
std::string to_trim{"hello"};
char left_char = 'h';
boost::algorithm::trim_left_if(to_trim, /*left_char?*/);
在上面的最后一行中,我需要一种方法来传递char 值。我环顾四周,但在 Boost 或 STL 中没有看到用于简单比较两个任意值的通用谓词。我可以为此使用 lambda,但如果存在谓词,我更喜欢谓词。
我想在这里避免的一件事是使用boost::is_any_of() 或任何其他需要将left_char 转换为字符串的谓词。
【问题讨论】:
-
你不能使用 lambda 吗?
[&](char c) { return c == left_char; }. -
is_from_range(left_char, left_char)? -
@T.C.范围不是半开的?
-
@Yakk 不符合documentation。
-
@T.C.我有点明白为什么,但是嗯。