this post was submitted on 30 Mar 2024
5 points (100.0% liked)

C & C++

889 readers
6 users here now

founded 5 years ago
MODERATORS
 

Yes, it is probably a weird question, but I tried a lot, and I started to think that maybe is impossible to overload this template function properly:

#include <iterator>

class Foo
{
private:
    const int arr[5] = {10, 20, 30, 40, 50};
public:
    const int* begin() const { return arr; }

friend auto std::begin<>(const Foo &f) -> decltype(f.begin());
}

It always throw the same error (in GCC 12.2.0):

main.cxx:10:13: error: template-id ‘begin<>’ for ‘const int* std::begin<>(const Foo&)’ does not match any template declaration

I just wanna know if is possible do things like this. Thanks.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 7 months ago

Off topic, but if you're injecting std into friends, they won't be friends long.