From: Brian Braatz (brianb_at_[hidden])
Date: 2005-03-30 11:28:58
I have been reading (ahem and re-reading) "C++ Template Metaprogramming"
I have a problem I am trying to solve and was up late last night looking
for the answer to jump out at me. If nothing else this helps me as I
tend to re-read the same chapters over and over.
Here is what I am trying to do
In working on coded I am adding to the proposed Boost Profiler (started
by Chris Diggings, inherited by yours truly).
I am using RAII all "over" my program in the extensions I am adding to
the profiler. This puts me in a spot where I have MACROs which stuff the
profile points in the program. Now the problem is I would like to be
able to add a template param to the TYPE of the profile points which
gives it the initialization code for the STREAM it is using. The problem
is since the objects themselves get created ALL OVER the program, I
don't have a single point of construction (because I am using RAII to
track the life cycles inside the functions themselves).
I.e. I want to be able to use Boost.IOstreams or ofstream or whatever
for these objects.I just need to , at the TYPE DEFINITION be able to
define how to initialize this passed stream.
I need to be able to do something like this
Template <typename STREAMTYPE, typename INITFUNCTOR>
INITFUNCTOR f(outstream); // open the file, init
iostreams , or whatever
I can always pass in a functor, but what I really want for Christmas is
to be able to
bind(&std::ofstream::open,_1,"MyFile.txt") > MyNewClass;
This doesn't work because bind returns an actual OBJECT instead of a
(intuitively - it would be cool if I could say bind(...)::Type which
would give me the TYPE of the generated functor)
SO that led me to be up until 3 am reading about mpl::lambda. I am still
trying to determine if THAT can be used in place, but the dots are not
connecting for me yet.
Any suggestions or directions pointed GREATLY appreciated.
Is there a way to make this work with MPL::Lambda?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk