@@ -82,17 +82,17 @@ class Conf {
82
82
* c) network
83
83
* - This method should not throw.
84
84
*/
85
- bool is_from_file () const { return !file_.empty (); }
85
+ [[nodiscard]] bool is_from_file () const { return !file_.empty (); }
86
86
87
87
/* *
88
88
* Return the file associated with this configuration.
89
89
*/
90
- const std::string& file () const { return file_; }
90
+ [[nodiscard]] const std::string& file () const { return file_; }
91
91
92
92
/* *
93
93
* Return whether this configuration is empty.
94
94
*/
95
- bool is_empty () const { return data_.is_null (); }
95
+ [[nodiscard]] bool is_empty () const { return data_.is_null (); }
96
96
97
97
/* *
98
98
* Return a reference to the JSON.
@@ -113,25 +113,25 @@ class Conf {
113
113
/* *
114
114
* Return the root of the current JSON as a JSON pointer.
115
115
*/
116
- std::string root () const { return (root_.empty () ? " /" : root_); }
116
+ [[nodiscard]] std::string root () const { return (root_.empty () ? " /" : root_); }
117
117
118
118
/* *
119
119
* Return whether the key is present in the configuration.
120
120
*
121
121
* - This method should not throw.
122
122
*/
123
- bool has (const std::string& key) const { return data_.count (key) != 0 ; }
124
- bool has (const JsonPointer& key) const ;
125
- bool has_pointer (const std::string& key) const { return has (JsonPointer (key)); }
123
+ [[nodiscard]] bool has (const std::string& key) const { return data_.count (key) != 0 ; }
124
+ [[nodiscard]] bool has (const JsonPointer& key) const ;
125
+ [[nodiscard]] bool has_pointer (const std::string& key) const { return has (JsonPointer (key)); }
126
126
127
127
/* *
128
128
* Return a new Conf basing off the JSON pointer.
129
129
*
130
130
* - Throws a ConfError if the key cannot be found.
131
131
*/
132
- Conf at (const std::string& key) const ;
133
- Conf at (const JsonPointer& key) const ;
134
- Conf at_pointer (const std::string& key) const { return at (JsonPointer (key)); }
132
+ [[nodiscard]] Conf at (const std::string& key) const ;
133
+ [[nodiscard]] Conf at (const JsonPointer& key) const ;
134
+ [[nodiscard]] Conf at_pointer (const std::string& key) const { return at (JsonPointer (key)); }
135
135
136
136
/* *
137
137
* Erase a key from the Conf if it exists and return the number of elements
@@ -146,15 +146,15 @@ class Conf {
146
146
*
147
147
* - Throws a ConfError if the object is not an array.
148
148
*/
149
- std::vector<Conf> to_array () const ;
149
+ [[nodiscard]] std::vector<Conf> to_array () const ;
150
150
151
151
/* *
152
152
* Return a value of type T.
153
153
*
154
154
* - Throws a ConfError if the key is of the wrong type.
155
155
*/
156
156
template <typename T>
157
- T get () const {
157
+ [[nodiscard]] T get () const {
158
158
try {
159
159
return data_.get <T>();
160
160
} catch (nlohmann::detail::type_error&) {
@@ -168,7 +168,7 @@ class Conf {
168
168
* - Throws a ConfError if the key cannot be found or is wrong type.
169
169
*/
170
170
template <typename T>
171
- T get (const std::string& key) const {
171
+ [[nodiscard]] T get (const std::string& key) const {
172
172
try {
173
173
return data_.at (key).get <T>();
174
174
} catch (nlohmann::detail::out_of_range&) {
@@ -179,7 +179,7 @@ class Conf {
179
179
}
180
180
181
181
template <typename T>
182
- T get (const JsonPointer& key) const {
182
+ [[nodiscard]] T get (const JsonPointer& key) const {
183
183
try {
184
184
return data_.at (key).get <T>();
185
185
} catch (nlohmann::detail::out_of_range&) {
@@ -190,7 +190,7 @@ class Conf {
190
190
}
191
191
192
192
template <typename T>
193
- T get_pointer (const std::string& key) const {
193
+ [[nodiscard]] T get_pointer (const std::string& key) const {
194
194
return get<T>(JsonPointer (key));
195
195
}
196
196
@@ -199,7 +199,7 @@ class Conf {
199
199
* key cannot be found.
200
200
*/
201
201
template <typename T>
202
- T get_or (const std::string& key, T def) const {
202
+ [[nodiscard]] T get_or (const std::string& key, T def) const {
203
203
if (!data_.count (key)) {
204
204
return def;
205
205
}
@@ -211,7 +211,7 @@ class Conf {
211
211
}
212
212
213
213
template <typename T>
214
- T get_or (const JsonPointer& key, T def) const {
214
+ [[nodiscard]] T get_or (const JsonPointer& key, T def) const {
215
215
try {
216
216
return data_.at (key).get <T>();
217
217
} catch (nlohmann::detail::out_of_range&) {
@@ -222,7 +222,7 @@ class Conf {
222
222
}
223
223
224
224
template <typename T>
225
- T get_pointer_or (const std::string& key, T def) const {
225
+ [[nodiscard]] T get_pointer_or (const std::string& key, T def) const {
226
226
return get_or (key, def);
227
227
}
228
228
@@ -318,8 +318,8 @@ class Conf {
318
318
* - If the path is relative and file is not stdin, return relative to
319
319
* the file.
320
320
*/
321
- std::filesystem::path resolve_file (const std::filesystem::path& filename) const ;
322
- std::string resolve_file (const std::string& filename) const ;
321
+ [[nodiscard]] std::filesystem::path resolve_file (const std::filesystem::path& filename) const ;
322
+ [[nodiscard]] std::string resolve_file (const std::string& filename) const ;
323
323
324
324
template <typename ... Args>
325
325
[[noreturn]] void throw_error (std::string_view format, Args&&... args) const {
0 commit comments