struct emptystruct
{
};
struct structWithInt
{
int a;
};
class classWithPrivateMember
{
int a;
};
class emptyClass
{
};
class classWithPtr
{
public:
void* ptr;
int a;
};
class classWithStaticPtr
{
public:
static void* ptr;
int a;
};
class classContainingClassWithPtr
{
public:
classWithPtr c;
};
int main()
{
std::cout << "std::tr1::is_pod<int>::value = " << std::boolalpha
<< std::tr1::is_pod<int>::value << std::endl;
std::cout << "std::tr1::is_pod<emptystruct>::value = " <<
std::boolalpha << std::tr1::is_pod<emptystruct>::value << std::endl;
std::cout << "std::tr1::is_pod<structWithInt>::value = " <<
std::boolalpha << std::tr1::is_pod<structWithInt>::value << std::endl;
std::cout << "std::tr1::is_pod<emptyClass>::value = " <<
std::boolalpha << std::tr1::is_pod<emptyClass>::value << std::endl;
std::cout << "std::tr1::is_pod<classWithPrivateMember>::value = " <<
std::boolalpha << std::tr1::is_pod<classWithPrivateMember>::value <<
std::endl;
std::cout << "std::tr1::is_pod<classWithPtr>::value = " <<
std::boolalpha << std::tr1::is_pod<classWithPtr>::value << std::endl;
std::cout << "std::tr1::is_pod<classWithStaticPtr>::value = " <<
std::boolalpha << std::tr1::is_pod<classWithStaticPtr>::value <<
std::endl;
std::cout << "std::tr1::is_pod<classContainingClassWithPtr>::value =
" << std::boolalpha <<
std::tr1::is_pod<classContainingClassWithPtr>::value << std::endl;
}
All the above except is_pod<int> return false? Is is_pod guarantee to
return true for PODs? I am using gcc 4.2.4
Thanks,
MSR
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
> All the above except is_pod<int> return false? Is is_pod guarantee to
> return true for PODs? I am using gcc 4.2.4
I think is_pod is allowed to return false negatives to accommodate for
the difficulties of implementing it.
GCC doesn't provide the necessary mechanisms for a library to check
whether a type is a POD, so the library does what it can.
There's no such guarantee in TR1. It is required that is_pod to be
true when is_scalar or is_void are true, but otherwise it's a quality
of implementation issue.
[...]
> All the above except is_pod<int> return false?
Which is maybe quite reasonable for your gcc 4.2.4.
Did you check gcc 4.2.4's tr1 status before writing
the test code?
Also please note for tr1's is_pod, implementation
can choose true or false freely, except that the
following should be true:
is_pod <Ty>::value >=
(is_scalar <Ty>:: value || is_void <Ty>::value)
is_pod <Ty>::value == is_pod <const Ty>::value
is_pod <Ty>::value == is_pod <volatile Ty>::value
is_pod <Ty>::value ==
is_pod <remove_extent <Ty>::type>::value
Check Pete's book for further details please.
> Is is_pod guarantee to return true for PODs?
No. As explained above, if even is_pod reports
false, the type maybe is a POD.
BTW, if is_pod returns true, then type should
be a POD.
> I am using gcc 4.2.4
Try a new one please.
My gcc 4.4.0 said:
$ ./pod
std::tr1::is_pod<int>::value = true
std::tr1::is_pod<emptystruct>::value = true
std::tr1::is_pod<structWithInt>::value = true
std::tr1::is_pod<emptyClass>::value = true
std::tr1::is_pod<classWithPrivateMember>::value = false
std::tr1::is_pod<classWithPtr>::value = true
std::tr1::is_pod<classWithStaticPtr>::value = true
std::tr1::is_pod<classContainingClassWithPtr>::value = true
Regards,
Jiang
GCC 4.3.1 provides the __is_pod extension:
#include <iostream>
using namespace std;
struct a{};
class b{};
struct c{ int i; };
struct d{ private: int j; };
struct e: public c{ int j;};
struct f { c i;};
int main()
{
cout << __is_pod(a) << endl;
cout << __is_pod(b) << endl;
cout << __is_pod(c) << endl;
cout << __is_pod(d) << endl;
cout << __is_pod(e) << endl;
cout << __is_pod(f) << endl;
}
prints:
1
1
1
0
0
1
tr1/type_traits is implemented using __is_pod. For 4.2.1, at any rate,
the implementation doesn't use __is_pod.
-Ed
--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)
/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage