Skip to content

Commit

Permalink
Merge pull request #1230 from mandreyel/lambda-unevaluated-context-fix
Browse files Browse the repository at this point in the history
Move lambda out of unevaluated context
  • Loading branch information
nlohmann authored Sep 10, 2018
2 parents ebb3c03 + 6b5334c commit 186c747
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,18 @@ class input_adapter
int>::type = 0>
input_adapter(IteratorType first, IteratorType last)
{
#ifndef NDEBUG
// assertion to check that the iterator range is indeed contiguous,
// see http://stackoverflow.com/a/35008842/266378 for more discussion
assert(std::accumulate(
first, last, std::pair<bool, int>(true, 0),
[&first](std::pair<bool, int> res, decltype(*first) val)
const auto is_contiguous = std::accumulate(
first, last, std::pair<bool, int>(true, 0),
[&first](std::pair<bool, int> res, decltype(*first) val)
{
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
return res;
}).first);
}).first;
assert(is_contiguous);
#endif

// assertion to check that each element is 1 byte long
static_assert(
Expand Down
11 changes: 7 additions & 4 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2184,15 +2184,18 @@ class input_adapter
int>::type = 0>
input_adapter(IteratorType first, IteratorType last)
{
#ifndef NDEBUG
// assertion to check that the iterator range is indeed contiguous,
// see http://stackoverflow.com/a/35008842/266378 for more discussion
assert(std::accumulate(
first, last, std::pair<bool, int>(true, 0),
[&first](std::pair<bool, int> res, decltype(*first) val)
const auto is_contiguous = std::accumulate(
first, last, std::pair<bool, int>(true, 0),
[&first](std::pair<bool, int> res, decltype(*first) val)
{
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
return res;
}).first);
}).first;
assert(is_contiguous);
#endif

// assertion to check that each element is 1 byte long
static_assert(
Expand Down

0 comments on commit 186c747

Please sign in to comment.