#include <iostream>
template <typename T>
class has_size {
private:
typedef char Yes;
typedef Yes No[2];
template<typename C> static auto Test(void*)
-> decltype(size_t{std::declval<C const>().size()}, Yes{});
template<typename> static No& Test(...);
public:
static bool const value = sizeof(Test<T>(0)) == sizeof(Yes);
};
struct NoSize {};
struct Sized { size_t size() const { return 0; } };
struct BadlySized { int size() { return 0; } };
struct MultiSized { size_t size() const { return 0; } int size(int) { return 0; } };
int main() {
std::cout << "NoSize: " << has_size<NoSize>::value << "\n";
std::cout << "Sized: " << has_size<Sized>::value << "\n";
std::cout << "BadlySized: " << has_size<BadlySized>::value << "\n";
std::cout << "MultiSized: " << has_size<MultiSized>::value << "\n";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CmNsYXNzIGhhc19zaXplIHsKcHJpdmF0ZToKICB0eXBlZGVmIGNoYXIgWWVzOwogIHR5cGVkZWYgWWVzIE5vWzJdOwoKICB0ZW1wbGF0ZTx0eXBlbmFtZSBDPiBzdGF0aWMgYXV0byBUZXN0KHZvaWQqKQogICAgLT4gZGVjbHR5cGUoc2l6ZV90e3N0ZDo6ZGVjbHZhbDxDIGNvbnN0PigpLnNpemUoKX0sIFllc3t9KTsKCiAgdGVtcGxhdGU8dHlwZW5hbWU+IHN0YXRpYyBObyYgVGVzdCguLi4pOwoKcHVibGljOgogICAgc3RhdGljIGJvb2wgY29uc3QgdmFsdWUgPSBzaXplb2YoVGVzdDxUPigwKSkgPT0gc2l6ZW9mKFllcyk7Cn07CgpzdHJ1Y3QgTm9TaXplIHt9OwoKc3RydWN0IFNpemVkIHsgc2l6ZV90IHNpemUoKSBjb25zdCB7IHJldHVybiAwOyB9IH07CgpzdHJ1Y3QgQmFkbHlTaXplZCB7IGludCBzaXplKCkgeyByZXR1cm4gMDsgfSB9OwoKc3RydWN0IE11bHRpU2l6ZWQgeyBzaXplX3Qgc2l6ZSgpIGNvbnN0IHsgcmV0dXJuIDA7IH0gaW50IHNpem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