mirror of
https://github.com/nlohmann/json.git
synced 2026-03-11 03:31:24 +00:00
meta: fix is_compatible/constructible traits (#3020)
The previous version relied on the existence of an 'iterator' type. As mentioned in comments, this is not the proper way to do it and causes issues with certain types (e.g. views from range-v3). Add a 'is_range' trait that properly detects the return type of 'begin'/'end', and use it in instead.
This commit is contained in:
@@ -850,4 +850,34 @@ TEST_CASE("Issue #1237")
|
||||
static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class no_iterator_type
|
||||
{
|
||||
public:
|
||||
no_iterator_type(std::initializer_list<int> l)
|
||||
: _v(l)
|
||||
{}
|
||||
|
||||
std::vector<int>::const_iterator begin() const
|
||||
{
|
||||
return _v.begin();
|
||||
}
|
||||
|
||||
std::vector<int>::const_iterator end() const
|
||||
{
|
||||
return _v.end();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<int> _v;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("compatible array type, without iterator type alias")
|
||||
{
|
||||
no_iterator_type vec{1, 2, 3};
|
||||
json j = vec;
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
Reference in New Issue
Block a user