#include <iostream>
#include <type_traits>
struct A
{
void foo() { std::cout << "A::foo()\n" ; }
void foo() const { std::cout << "A::foo() const\n" ; }
};
template < typename T > struct B
{
void bar() { const_cast<T&>(data).foo() ; }
private: typename std::remove_const<T>::type data ;
};
int main()
{
B<A> x ; x.bar() ; // A::foo()
B<const A> y ; y.bar() ; // A::foo() const
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CgpzdHJ1Y3QgQQp7CiAgICB2b2lkIGZvbygpIHsgc3RkOjpjb3V0IDw8ICJBOjpmb28oKVxuIiA7IH0KICAgIHZvaWQgZm9vKCkgY29uc3QgeyBzdGQ6OmNvdXQgPDwgIkE6OmZvbygpIGNvbnN0XG4iIDsgfQp9OwoKdGVtcGxhdGUgPCB0eXBlbmFtZSBUID4gc3RydWN0IEIKewogICAgdm9pZCBiYXIoKSB7IGNvbnN0X2Nhc3Q8VCY+KGRhdGEpLmZvbygpIDsgfQoKICAgIHByaXZhdGU6IHR5cGVuYW1lIHN0ZDo6cmVtb3ZlX2NvbnN0PFQ+Ojp0eXBlIGRhdGEgOwp9OwoKaW50IG1haW4oKQp7CiAgICBCPEE+IHggOyB4LmJhcigpIDsgLy8gQTo6Zm9vKCkKCiAgICBCPGNvbnN0IEE+IHkgOyB5LmJhcigpIDsgLy8gQTo6Zm9vKCkgY29uc3QKfQo=