Skip to content

Commit 6ec652d

Browse files
authored
Add convertFromString<vector<bool>> (#992)
1 parent 4d6f92a commit 6ec652d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ template <>
183183
template <>
184184
[[nodiscard]] std::vector<double> convertFromString<std::vector<double>>(StringView str);
185185

186+
// Boolean values separated by the character ";"
187+
template <>
188+
[[nodiscard]] std::vector<bool> convertFromString<std::vector<bool>>(StringView str);
189+
186190
// Strings separated by the character ";"
187191
template <>
188192
[[nodiscard]] std::vector<std::string>

src/basic_types.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ std::vector<double> convertFromString<std::vector<double>>(StringView str)
237237
return output;
238238
}
239239

240+
template <>
241+
std::vector<bool> convertFromString<std::vector<bool>>(StringView str)
242+
{
243+
auto parts = splitString(str, ';');
244+
std::vector<bool> output;
245+
output.reserve(parts.size());
246+
for(const StringView& part : parts)
247+
{
248+
output.push_back(convertFromString<bool>(part));
249+
}
250+
return output;
251+
}
252+
240253
template <>
241254
std::vector<std::string> convertFromString<std::vector<std::string>>(StringView str)
242255
{

0 commit comments

Comments
 (0)