|
Boost : |
Subject: Re: [boost] Generic lazy loader library interest
From: John Bellone (jb_at_[hidden])
Date: 2010-08-26 21:02:43
Hey Dave,
It is not a code loader (or class loader) in the sense of Java. This is a
design pattern which delays execution (allocation) until the object is first
needed. Wikipedia would have a much better explanation than I could (
http://en.wikipedia.org/wiki/Lazy_loading). I currently have a example up on
my Github repository, but there is still work to be done to make it better
so I figured I'd put the feelers out to see if there is interest.
I have a post regarding it on my blog (http://thoughtlessbanter.com/) and
I'll include a snippet from the example.
class Unique{public:
Unique()
: m_uuid(boost::uuids::random_generator()())
{
}
Unique(const boost::uuids::uuid& u)
: m_uuid(u)
{
}
const boost::uuids::uuid& uuid()
{
return m_uuid;
}private:
boost::uuids::uuid m_uuid;};
static void factory(boost::shared_ptr<Unique>& impl){
impl = boost::shared_ptr<Unique>(
new Unique(boost::uuids::nil_uuid()) );}
int main(int argc, char* argv[]){
thunk::lazy_loader<Unique> loader(&factory);
const boost::uuids::uuid& u = loader->uuid();
std::cout<<"uuid: "<<boost::lexical_cast<std::string>(u)<<std::endl;
return 0;}
Thanks,
jb
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk