Let\'s say I have the following class X where I want to return access to an internal member:
class Z
{
// details
};
class X
{
std::vec
Here's a C++17 version of the template static helper function, with and optional SFINAE test.
#include
#define REQUIRES(...) class = std::enable_if_t<(__VA_ARGS__)>
#define REQUIRES_CV_OF(A,B) REQUIRES( std::is_same_v< std::remove_cv_t< A >, B > )
class Foobar {
private:
int something;
template
static auto& _getSomething(FOOBAR& self, int index) {
// big, non-trivial chunk of code...
return self.something;
}
public:
auto& getSomething(int index) { return _getSomething(*this, index); }
auto& getSomething(int index) const { return _getSomething(*this, index); }
};
Full version: https://godbolt.org/z/mMK4r3