//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  https://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  https://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <iostream>

class Base {
 public:
  // member function with traditional *this:
  void mem() {
    if constexpr (std::same_as<decltype(this), Base*>) {
      std::cout << "Base::mem() compiles for *this of type 'Base'\n";  
    }
    else {
      std::cout << "Base::mem() compiles for *this of a DERIVED type\n"; 
    }
  }

  // member function with deduced object parameter:
  void ded(this auto& self) {
    if constexpr (std::same_as<std::remove_cvref_t<decltype(self)>, Base>) {
      std::cout << "Base::ded() compiles for self  of 'Base' type\n";  
    }
    else {
      std::cout << "Base::ded() compiles for self  of a DERIVED type\n"; 
    }
  }
};

class Der : public Base {
};

int main()
{
  Der d;
  d.mem();   // call member function with implicit object *this
  d.ded();   // call member function with explicit object parameter 
}

