Skip to content

Commit 8cec462

Browse files
committed
fix error and add nodiscard
1 parent 77c0571 commit 8cec462

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,60 +83,65 @@ inline T convertFromString(StringView /*str*/)
8383
type_name);
8484
}
8585

86-
template <>
86+
template <> [[nodiscard]]
8787
std::string convertFromString<std::string>(StringView str);
8888

89-
template <>
89+
template <> [[nodiscard]]
9090
const char* convertFromString<const char*>(StringView str);
9191

92-
template <>
92+
template <> [[nodiscard]]
9393
int convertFromString<int>(StringView str);
9494

95-
template <>
95+
template <> [[nodiscard]]
9696
unsigned convertFromString<unsigned>(StringView str);
9797

98-
template <>
98+
template <> [[nodiscard]]
9999
long convertFromString<long>(StringView str);
100100

101-
template <>
101+
template <> [[nodiscard]]
102102
unsigned long convertFromString<unsigned long>(StringView str);
103103

104-
template <>
104+
template <> [[nodiscard]]
105105
float convertFromString<float>(StringView str);
106106

107-
template <>
107+
template <> [[nodiscard]]
108108
double convertFromString<double>(StringView str);
109109

110-
template <> // Integer numbers separated by the character ";"
110+
// Integer numbers separated by the character ";"
111+
template <> [[nodiscard]]
111112
std::vector<int> convertFromString<std::vector<int>>(StringView str);
112113

113-
template <> // Real numbers separated by the character ";"
114+
// Real numbers separated by the character ";"
115+
template <> [[nodiscard]]
114116
std::vector<double> convertFromString<std::vector<double>>(StringView str);
115117

116-
template <> // This recognizes either 0/1, true/false, TRUE/FALSE
118+
// This recognizes either 0/1, true/false, TRUE/FALSE
119+
template <> [[nodiscard]]
117120
bool convertFromString<bool>(StringView str);
118121

119-
template <> // Names with all capital letters
122+
// Names with all capital letters
123+
template <> [[nodiscard]]
120124
NodeStatus convertFromString<NodeStatus>(StringView str);
121125

122-
template <> // Names with all capital letters
126+
// Names with all capital letters
127+
template <> [[nodiscard]]
123128
NodeType convertFromString<NodeType>(StringView str);
124129

125-
template <>
130+
template <> [[nodiscard]]
126131
PortDirection convertFromString<PortDirection>(StringView str);
127132

128133
typedef std::function<Any(StringView)> StringConverter;
129134

130135
typedef std::unordered_map<const std::type_info*, StringConverter> StringConvertersMap;
131136

132137
// helper function
133-
template <typename T>
138+
template <typename T> [[nodiscard]]
134139
inline StringConverter GetAnyFromStringFunctor()
135140
{
136141
return [](StringView str) { return Any(convertFromString<T>(str)); };
137142
}
138143

139-
template <>
144+
template <> [[nodiscard]]
140145
inline StringConverter GetAnyFromStringFunctor<void>()
141146
{
142147
return {};
@@ -153,10 +158,8 @@ std::string toStr(const T& value)
153158
return std::to_string(value);
154159
}
155160

156-
template <> [[nodiscard]] inline
157-
std::string toStr<bool>(const bool& value) {
158-
return value ? "true" : "false";
159-
}
161+
template <> [[nodiscard]]
162+
std::string toStr<bool>(const bool& value);
160163

161164
template <> [[nodiscard]]
162165
std::string toStr<std::string>(const std::string& value);
@@ -172,9 +175,6 @@ std::string toStr(BT::NodeStatus status, bool colored);
172175

173176
std::ostream& operator<<(std::ostream& os, const BT::NodeStatus& status);
174177

175-
/**
176-
* @brief toStr converts NodeType to string.
177-
*/
178178
template <> [[nodiscard]]
179179
std::string toStr<BT::NodeType>(const BT::NodeType& type);
180180

include/behaviortree_cpp/tree_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ enum class PostCond
6363
COUNT_
6464
};
6565

66-
template <>
66+
template <> [[nodiscard]]
6767
std::string toStr<BT::PostCond>(const BT::PostCond& status);
6868

69-
template <>
69+
template <> [[nodiscard]]
7070
std::string toStr<BT::PreCond>(const BT::PreCond& status);
7171

7272
using ScriptingEnumsRegistry = std::unordered_map<std::string, int>;

src/basic_types.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ std::string toStr<NodeStatus>(const NodeStatus& status)
2525
return "";
2626
}
2727

28-
std::string toStr(const std::string &value)
28+
template <> [[nodiscard]]
29+
std::string toStr<bool>(const bool& value) {
30+
return value ? "true" : "false";
31+
}
32+
33+
template <>
34+
std::string toStr<std::string>(const std::string &value)
2935
{
3036
return value;
3137
}

0 commit comments

Comments
 (0)