|
Boost : |
From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-09-30 10:50:54
David Abrahams wrote:
> All types have a copy_ctor. It's just a question of whether it's
> private or not, and I'm not sure that's detectable without causing an
> error.
I've just typed something but I'm not sure whether it should work as
expected. Intel 7.1 compiles it and prints 1 in both cases. Comeau online
compiles it as well but I can't run the test.
I'll think about this at home with a printed standard in hands.
struct no_copy_ctor {};
template<class T>
struct tester : T
{
tester();
tester(const tester& other)
: T(static_cast<T const&>(other)) {}
operator no_copy_ctor();
};
typedef char yes_type;
typedef char (&no_type)[2];
template<class T>
yes_type test_copy_ctor(tester<T>);
no_type test_copy_ctor(no_copy_ctor);
template<class T>
struct has_copy_ctor
{
static const bool value = sizeof(test_copy_ctor(tester<T>())) ==
sizeof(yes_type);
};
// test program
#include <iostream>
class X {};
class Y
{
Y(const Y&);
};
int main()
{
std::cout << has_copy_ctor<X>::value << '\n';
std::cout << has_copy_ctor<Y>::value << '\n';
}
-- Alexander Nasonov Remove minus and all between minus and at from my e-mail for timely response
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk