I tried this code at www.ideone.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <iomanip>
#include <type_traits>
struct A
{
private:
A(){}
public:
static A & create()
{
static A a;
std::cout << std::boolalpha << std::is_default_constructible<A>::value << std::endl;
return a;
}
friend void f( A )
{
std::cout << std::boolalpha << std::is_default_constructible<A>::value << std::endl;
}
};
int main()
{
f( A::create() );
}
|
and I got compilation errors
usr/include/c++/4.7/type_traits: In instantiation of ‘struct std::__is_default_constructible_impl<A>’:
/usr/include/c++/4.7/type_traits:116:12: required from ‘struct std::__and_<std::__not_<std::is_void<A> >, std::__is_default_constructible_impl<A> >’
/usr/include/c++/4.7/type_traits:682:12: required from ‘struct std::__is_default_constructible_atom<A>’
/usr/include/c++/4.7/type_traits:703:12: required from ‘struct std::__is_default_constructible_safe<A, false>’
/usr/include/c++/4.7/type_traits:709:12: required from ‘struct std::is_default_constructible<A>’
prog.cpp:13:84: required from here
prog.cpp:8:13: error: ‘A::A()’ is private
MS VS 2010 has no is_default_constructible in namespace std.
So could some one compile it in GCC 4.8.
But in any case I think accessibility of a class depends of a context. The definition of defaultconstructibility says nothing about the access control. Sp the realization of std::is_default_constructibility can not satisfies the definition.