Skip to content

Commit 2907ba9

Browse files
committed
Allow constructon of json_stringt from irep_idt.
Allow constructon of `jsont`/`json_stringt` from `std::string`/`irep_idt`/string literals. This allows for a reduction in the amount of boilerplate code. For example instead of writing ``` result["file"] = json_stringt(id2string(location.get_file())); ``` we could write ``` result["file"] = json_stringt(location.get_file()); ``` The constructor from string literal is required when constructors from both `std::string` and `irep_idt` are provided. Otherwise the compiler does not know whether to implicitly convert string literals into a `std:string` or a `irep_idt`.
1 parent ce674b5 commit 2907ba9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/util/json.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Author: Daniel Kroening, [email protected]
1515
#include <iosfwd>
1616
#include <string>
1717

18+
#include "irep.h"
19+
1820
class json_objectt;
1921
class json_arrayt;
2022

@@ -182,8 +184,20 @@ class json_arrayt:public jsont
182184
class json_stringt:public jsont
183185
{
184186
public:
185-
explicit json_stringt(const std::string &_value):
186-
jsont(kindt::J_STRING, _value)
187+
explicit json_stringt(std::string _value):
188+
jsont(kindt::J_STRING, std::move(_value))
189+
{
190+
}
191+
192+
#ifndef USE_STD_STRING
193+
explicit json_stringt(const irep_idt &_value)
194+
: jsont(kindt::J_STRING, id2string(_value))
195+
{
196+
}
197+
#endif
198+
199+
/// Constructon from string literal.
200+
explicit json_stringt(const char *_value) : jsont(kindt::J_STRING, _value)
187201
{
188202
}
189203
};

0 commit comments

Comments
 (0)