7
submitted 5 months ago by RuikkaaPrus@lemmy.ml to c/cpp@lemmy.ml

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
[-] southsamurai@sh.itjust.works 2 points 5 months ago

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

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

C & C++

843 readers
2 users here now

founded 5 years ago
MODERATORS