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:
Théo DELRIEU
2021-10-07 12:32:25 +02:00
committed by GitHub
parent 62f2997b79
commit 80df5e8de6
7 changed files with 321 additions and 132 deletions

View File

@@ -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