I'm trying to glean the return type of a class method inside a class that could either be const or non-const. This information is transfered to another calling class object where I try to use decltype() to resolve the return type. However, it doesn't compile with the following errors (among other but I they all boil down to this issue):
Error (gcc 11.2):
<source>:209:11: error: 'decltype' cannot resolve address of overloaded function
209 | using proxy_iter_type = decltype(&Container::begin);
My Code:
#include <iostream>
#include <string>
#include <unordered_map>
template<typename Container>
class A_Iterator
{
public:
using proxy_type = typename Container::proxy_type;
using proxy_iter_type = decltype(&Container::begin);
public:
A_Iterator(proxy_iter_type it) : it_{it} {};
private:
proxy_iter_type it_;
};
class A
{
public:
using value_type = std::pair<std::string, std::string>;
using proxy_type = std::unordered_map<int, value_type>;
using const_iterator = A_Iterator<const A>;
using iterator = A_Iterator<A>;
public:
iterator begin() { return iterator( data_.begin() ); }
const_iterator begin() const { return const_iterator( data_.begin() ); }
private:
proxy_type data_;
};
How can I get this to work?