Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d431462800 |
No files matched your search
@@ -1312,23 +1312,15 @@ struct can_compare_ne_either_order : std::integral_constant < bool,
|
|||||||
can_compare_ne_impl<IteratorType, SentinelType>::value ||
|
can_compare_ne_impl<IteratorType, SentinelType>::value ||
|
||||||
can_compare_ne_reversed<IteratorType, SentinelType>::value > {};
|
can_compare_ne_reversed<IteratorType, SentinelType>::value > {};
|
||||||
|
|
||||||
// Two kinds of SentinelType are excluded explicitly:
|
// std::nullptr_t is excluded explicitly: a literal `nullptr` passed as a
|
||||||
//
|
// trailing default argument (e.g. parse(s, nullptr, ...)) must never be
|
||||||
// - std::nullptr_t: a literal `nullptr` passed as a trailing default argument
|
// mistaken for a sentinel, and some compilers (e.g. GCC 4.8) unreliably
|
||||||
// (e.g. parse(s, nullptr, ...)) must never be mistaken for a sentinel, and
|
// SFINAE the `operator!=` detection above for std::nullptr_t against
|
||||||
// some compilers (e.g. GCC 4.8) unreliably SFINAE the `operator!=` detection
|
// container/string types, which would otherwise make such calls ambiguous
|
||||||
// above for std::nullptr_t against container/string types, which would
|
// with the compatible-input overload.
|
||||||
// otherwise make such calls ambiguous with the compatible-input overload.
|
|
||||||
// - function pointers and functions: a parser callback passed as plain function
|
|
||||||
// (e.g. parse(s, cb)) is never a sentinel. The callback's parameter types
|
|
||||||
// make basic_json an associated class, so ADL finds the friend
|
|
||||||
// operator!=(const_reference, ScalarType) of basic_json, which makes
|
|
||||||
// `s != cb` well-formed (both convert to basic_json) and would select the
|
|
||||||
// iterator/sentinel overload.
|
|
||||||
template<typename IteratorType, typename SentinelType>
|
template<typename IteratorType, typename SentinelType>
|
||||||
struct can_compare_ne : std::integral_constant < bool,
|
struct can_compare_ne : std::integral_constant < bool,
|
||||||
!std::is_same<SentinelType, std::nullptr_t>::value &&
|
!std::is_same<SentinelType, std::nullptr_t>::value &&
|
||||||
!std::is_function<typename std::remove_pointer<SentinelType>::type>::value &&
|
|
||||||
can_compare_ne_either_order<IteratorType, SentinelType>::value > {};
|
can_compare_ne_either_order<IteratorType, SentinelType>::value > {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
Generated
+6
-14
@@ -10421,23 +10421,15 @@ struct can_compare_ne_either_order : std::integral_constant < bool,
|
|||||||
can_compare_ne_impl<IteratorType, SentinelType>::value ||
|
can_compare_ne_impl<IteratorType, SentinelType>::value ||
|
||||||
can_compare_ne_reversed<IteratorType, SentinelType>::value > {};
|
can_compare_ne_reversed<IteratorType, SentinelType>::value > {};
|
||||||
|
|
||||||
// Two kinds of SentinelType are excluded explicitly:
|
// std::nullptr_t is excluded explicitly: a literal `nullptr` passed as a
|
||||||
//
|
// trailing default argument (e.g. parse(s, nullptr, ...)) must never be
|
||||||
// - std::nullptr_t: a literal `nullptr` passed as a trailing default argument
|
// mistaken for a sentinel, and some compilers (e.g. GCC 4.8) unreliably
|
||||||
// (e.g. parse(s, nullptr, ...)) must never be mistaken for a sentinel, and
|
// SFINAE the `operator!=` detection above for std::nullptr_t against
|
||||||
// some compilers (e.g. GCC 4.8) unreliably SFINAE the `operator!=` detection
|
// container/string types, which would otherwise make such calls ambiguous
|
||||||
// above for std::nullptr_t against container/string types, which would
|
// with the compatible-input overload.
|
||||||
// otherwise make such calls ambiguous with the compatible-input overload.
|
|
||||||
// - function pointers and functions: a parser callback passed as plain function
|
|
||||||
// (e.g. parse(s, cb)) is never a sentinel. The callback's parameter types
|
|
||||||
// make basic_json an associated class, so ADL finds the friend
|
|
||||||
// operator!=(const_reference, ScalarType) of basic_json, which makes
|
|
||||||
// `s != cb` well-formed (both convert to basic_json) and would select the
|
|
||||||
// iterator/sentinel overload.
|
|
||||||
template<typename IteratorType, typename SentinelType>
|
template<typename IteratorType, typename SentinelType>
|
||||||
struct can_compare_ne : std::integral_constant < bool,
|
struct can_compare_ne : std::integral_constant < bool,
|
||||||
!std::is_same<SentinelType, std::nullptr_t>::value &&
|
!std::is_same<SentinelType, std::nullptr_t>::value &&
|
||||||
!std::is_function<typename std::remove_pointer<SentinelType>::type>::value &&
|
|
||||||
can_compare_ne_either_order<IteratorType, SentinelType>::value > {};
|
can_compare_ne_either_order<IteratorType, SentinelType>::value > {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -531,8 +531,11 @@ TEST_CASE("alternative string type with json_view")
|
|||||||
CHECK(d.root().materialize() == expected);
|
CHECK(d.root().materialize() == expected);
|
||||||
CHECK(alt_json::parse(d.root().dump()) == expected);
|
CHECK(alt_json::parse(d.root().dump()) == expected);
|
||||||
|
|
||||||
|
// save() and load() do not exist on big-endian targets
|
||||||
|
#if !(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
const alt_editable_document loaded = alt_editable_document::load(d.save());
|
const alt_editable_document loaded = alt_editable_document::load(d.save());
|
||||||
CHECK(loaded.root().materialize() == expected);
|
CHECK(loaded.root().materialize() == expected);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3232,40 +3232,3 @@ TEST_CASE("object keys are delivered decoded and validated")
|
|||||||
CHECK(keys_of_format(std::string("\x87\xC3\x28\x91"), json::input_format_t::bon8).empty());
|
CHECK(keys_of_format(std::string("\x87\xC3\x28\x91"), json::input_format_t::bon8).empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// a plain function (not a lambda or std::function) used as parser callback
|
|
||||||
bool keep_everything_callback(int /*depth*/, json::parse_event_t /*event*/, json& /*parsed*/)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
TEST_CASE("a plain function is accepted as parser callback for containers")
|
|
||||||
{
|
|
||||||
// ADL finds basic_json's friend operator!= for "container != function
|
|
||||||
// pointer", which must not make the iterator/sentinel overloads viable
|
|
||||||
|
|
||||||
const json expected = {1, 2};
|
|
||||||
const std::string text = "[1,2]";
|
|
||||||
const std::vector<std::uint8_t> bytes(text.begin(), text.end());
|
|
||||||
const std::vector<char> chars(text.begin(), text.end());
|
|
||||||
|
|
||||||
CHECK(json::parse(text, keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(text, &keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(std::string("[1,2]"), keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(bytes, keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(bytes, &keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(chars, keep_everything_callback) == expected);
|
|
||||||
CHECK(json::parse(text.begin(), text.end(), keep_everything_callback) == expected);
|
|
||||||
|
|
||||||
// the sentinel overloads (shared constraint of parse, accept, sax_parse and
|
|
||||||
// the from_* functions) are not viable for a container and a function
|
|
||||||
// pointer, but still are for iterator pairs
|
|
||||||
using callback_pointer = decltype(&keep_everything_callback);
|
|
||||||
CHECK_FALSE((nlohmann::detail::can_compare_ne<std::string, callback_pointer>::value));
|
|
||||||
CHECK_FALSE((nlohmann::detail::can_compare_ne<std::vector<std::uint8_t>, callback_pointer>::value));
|
|
||||||
CHECK((nlohmann::detail::can_compare_ne<std::string::const_iterator, std::string::const_iterator>::value));
|
|
||||||
CHECK((nlohmann::detail::can_compare_ne<const char*, const char*>::value));
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user