Boost Users :
Subject: [Boost-users] Metaprogamming question
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2011-07-08 06:17:10
I roughed out a function that will be a template that dispatches to one of several
different forms based on the nature of one of the arguments. It's fairly simple, each
helper call asking one question to further divide it up.
But, I want to write a dozen functions that all have similar (if not identical) issues.
So I want to abstract out the mixmaster and code that once. I'm thinking that I map the
argument to a "tag" that has many possible values, and have one set of overloaded
functions. It is easy to write the back end, as each function's tag is clear what that
case is for. Furthermore, I can make the tags empty structs that use an inheritance
pattern, so any forms I don't supply for some function will simply pick the more general one.
So, how do I write the metafunction that maps the type to the tag? I could follow my same
approach of one step at a time. But I wonder if a "switch" statement of some kind would
be clearer and easier. OTOH, I don't want to learn all of MPL just for one thing, and I
don't want to bog down the compilation speed. Is there something specific someone can
point me to?
Second, my pseudocode has a metafunction for telling me whether a type is a resizable
container. STL containers predate the modern style of metafunctions and use cumbersome
traits instead, but is there something around that I can use to tell that something is
supposed to be a STL container or specific categories of containers? I could just list
them all one by one, but type_traits already did that for me for a lot of things, and I'd
have to tell everyone how to meta-annotate their own classes that are supposed to work
"like" STL containers for algorithms.
Can I use something like enable_if to tell if a class has a push_back or resize function?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net