N
ng2010
From http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html and in the
section titled "POD Efficiencies", they give a workaround to the
defficiency/oversight in C++ that a POD cannot have constructors:
class uuid_class : public boost::uuids::uuid
{
public:
uuid_class() // def ctor shouldn't auto gen IMO else this
// class should be called auto_uuid or something
: boost::uuids::uuid(boost::uuids::random_generator()())
{}
explicit uuid_class(boost::uuids::uuid const& u)
: boost::uuids::uuid(u)
{}
operator boost::uuids::uuid() {
return static_cast<boost::uuids::uuid&>(*this);
}
operator boost::uuids::uuid() const {
return static_cast<boost::uuids::uuid const&>(*this);
}
};
What I don't understand is why the conversion operators in uuid_class
above guarantee anything more than just having defined boost::uuids::uuid
as a class with the constructors given above. The conversion operators
for the operators are just casting *this. Why the operators at all when
uuid_class IS a uuid?
section titled "POD Efficiencies", they give a workaround to the
defficiency/oversight in C++ that a POD cannot have constructors:
class uuid_class : public boost::uuids::uuid
{
public:
uuid_class() // def ctor shouldn't auto gen IMO else this
// class should be called auto_uuid or something
: boost::uuids::uuid(boost::uuids::random_generator()())
{}
explicit uuid_class(boost::uuids::uuid const& u)
: boost::uuids::uuid(u)
{}
operator boost::uuids::uuid() {
return static_cast<boost::uuids::uuid&>(*this);
}
operator boost::uuids::uuid() const {
return static_cast<boost::uuids::uuid const&>(*this);
}
};
What I don't understand is why the conversion operators in uuid_class
above guarantee anything more than just having defined boost::uuids::uuid
as a class with the constructors given above. The conversion operators
for the operators are just casting *this. Why the operators at all when
uuid_class IS a uuid?