Skip to content

[Question] copy assign json-container to vector #635

Description

@MrJakmer

Hi,

upon the recommendation of Niels Lohmann via e-mail, I want to refer to a question I asked on stackoverflow.

Let me share why I am asking that question: I am trying to search for a "lower bound" in a json-object. I assume this can't work since comparing with a double (or integer) isn't possible. That is why I need the conversion (via copy-assign) to a vector. If the question I referred to is not needed because you can solve the error with the lower bound (see code below), it would be great. But I think using vectors would still be relevant since it would be more efficient, if you use them multiple times.

See the following code:

#include "json.hpp"

using json = nlohmann::json;
using namespace std;


int main()
{

	const vector<double> v = { 0 , 10 , 20 ,100 };
	const json j(v);

	json::const_iterator low = lower_bound(j.cbegin(), j.cend(), 11);
	size_t lowerBoundIndex = low - j.begin();
	cout << lowerBoundIndex << endl;

	return 0;
}

I am using JSON for Modern C++ Version 2.1.1 with Microsoft Visual Studio 2015 Version 14.0.25431.01 Update 3 (regarding to your README the compiler should be okay). My operating system is Windows 7 SP1.

Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions