Skip to content
Snippets Groups Projects
Unverified Commit 87a998d4 authored by Enrico Guiraud's avatar Enrico Guiraud Committed by GitHub
Browse files

[cling] Better SFINAE check to print collection values


In order to specialize cling's value-printing logic for collections
we perform some SFINAE checks. Among other things, the checks
assert that `++(obj.begin())` is well-formed. That compiles for
`std::vector` and other collections with "fat" iterators, but does
not compile for collections that use raw pointers as iterators:

```cpp
auto beg(std::vector<int> &v) {
    return v.begin();
}

int *beg2(std::vector<int> &v) {
    return &v[0];
}

int main() {
    std::vector<int> v{1,2,3};
    beg(v) += 1;
    //beg2(v) += 1; // does not compile - beg2(v) is not an lvalue

    return 0;
}
```

Requiring instead `std::begin(obj)` to be well-formed should be
backward compatible and it should allow collections that use raw
pointers as iterators to also be pretty-printed by cling.

Co-authored-by: default avatarAxel Naumann <Axel.Naumann@cern.ch>
parent bb106670
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment