Skip to content

Using Boost.Test 1.65.0: no type named ‘value_type’ in ‘class Json::Value’ #671

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wolframroesler opened this issue Sep 12, 2017 · 3 comments

Comments

@wolframroesler
Copy link
Contributor

Hello,

I use Boost.Test, where until recently I could compare two Json::Value objects like this:

Json::Value actual = ...;
Json::Value expected = ...;
BOOST_TEST(actual==expected);

This stopped working when I upgraded to boost 1.65.0, where I now get the following compiler error:

In file included from /usr/local/include/boost/test/tools/collection_comparison_op.hpp:18:0,
                 from /usr/local/include/boost/test/test_tools.hpp:55,
                 from /usr/local/include/boost/test/unit_test.hpp:18,
                 from /home/wolfram/src/myfile.cpp:9:
/usr/local/include/boost/test/utils/is_forward_iterable.hpp: In instantiation of ‘struct boost::unit_test::bt_iterator_traits<Json::Value, true>’:
/usr/local/include/boost/test/tools/collection_comparison_op.hpp:437:5720:   required from ‘struct boost::test_tools::assertion::op::EQ<Json::Value, Json::Value, void>’
/usr/local/include/boost/test/tools/assertion.hpp:326:7:   required from ‘class boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<Json::Value&>, Json::Value&, boost::test_tools::assertion::op::EQ<Json::Value, Json::Value, void> >’
/home/wolfram/src/myfile.cpp:122:17:   required from here
/usr/local/include/boost/test/utils/is_forward_iterable.hpp:206:36: error: no type named ‘value_type’ in ‘class Json::Value’
     typedef typename T::value_type value_type;
                                    ^

One solution to make it compile is by adding the following line to Json::Value:

  typedef std::string value_type;

at the end of the initial list of typedefs, like so (using jsoncpp 1.8.3):

$ git diff 
diff --git a/include/json/json.h b/include/json/json.h
index ac2e884..de5a9df 100644
--- a/include/json/json.h
+++ b/include/json/json.h
@@ -634,6 +634,7 @@ public:
   typedef Json::LargestInt LargestInt;
   typedef Json::LargestUInt LargestUInt;
   typedef Json::ArrayIndex ArrayIndex;
+  typedef std::string value_type;
 
   static const Value& null;  ///< We regret this reference to a global instance; prefer the simpler Value().
   static const Value& nullRef;  ///< just a kludge for binary-compatibility; same as null

Now it builds and my tests pass. The question is, is this a good solution? I don't know enough about either how jsoncpp works or how BOOST_TEST works to tell.

Any help is appreciated. If I get a thumbs up from an expert on these matters I'll supply a merge request for this change.

Thanks!

PS: Another way to make my test program work is

BOOST_TEST(actual.toStyledString()==expected.toStyledString());

but I find this a lot less elegant than directly comparing the Json::Value objects.

@cdunn2001
Copy link
Contributor

Yes, I think adding that type would be fine. Please submit a pull-request.

@wolframroesler
Copy link
Contributor Author

Thanks, will submit the pull request later this week.

I can submit only this one line in the header file, however. You may want to add it to your test cases.

@wolframroesler
Copy link
Contributor Author

For the record, my build environment is:

  • Linux Mint 18
  • gcc 5.4.0
  • boost 1.65.0
  • JsonCpp 1.8.3

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants