Q:

Supporting multiple class interfaces through templating and SFINAE

I have a class which is derived off a class provided in a third party library.
Between versions of the third party library, they promoted a member in one of their classes from private to public, but in the move, they deprecated a method for accessing the member. Example:
// Old class
class A
{
    public:
        int &GetA() { return a;}
    private:
        int a;
};

// NewClass
class A
{
    public:
        int a;
};

My code uses an instance of A, but I want my code to work with either version, in case someone hasn't updated the library.
class B
{
   public:

   int & ReturnA() { return GetInnards(m_a);}

   private:
   A    m_a;

  // If m_a has a GetA member function call this:
  template(typename aType)
  int & GetInnards(aType &a) { return a.GetA(); }

  // If m_a does not have an GetA() member function, call this:
  template(typename aType)
  int & GetInnards(aType &a) { return a.m_a; }
};

It seems like I should be able to use SFINAE, but I'm missing something.
Also, there is nothing I can test with an #ifdef, so I can't go that route. I need to detect if a method exists, and or if a member is public.

A:

Well... given a couple of template functions as follows
template <typename A>
constexpr auto hasGetA (A const &)
   -> decltype( std::declval<A>().GetA(), std::true_type{} );

template <typename ... Ts>
constexpr std::false_type hasGetA (Ts const & ...);

you can write your method
  template <typename aType>
  auto GetInnards (aType & a)
     -> std::enable_if_t<true == decltype(hasGetA(a))::value, int &>
   { return a.GetA(); }

  template <typename aType>
  auto GetInnards (aType & a)
     -> std::enable_if_t<false == decltype(hasGetA(a))::value, int &>
   { return a.a; }

