Well, my mpl adventure continues.
I'm trying to place pair members of a sequence with their keys:
#include
David Greene wrote:
Well, my mpl adventure continues.
I'm trying to place pair members of a sequence with their keys:
#include
#include #include #include #include #include #include #include <iostream> #include <typeinfo>
using namespace boost; using namespace boost::mpl;
struct pair_base {};
template
struct pair_type : public pair , private pair_base {}; template<typename Sequence> struct replaceit { typedef typename replace_if< Sequence, is_base_and_derived
, key_type , _> >::type type; }; int main(void) { replaceit< vector< charm
You should be seeing a syntax error right here.
pair_type
>, pair_type > double > ::type toprint;
std::cout << typeid(toprint).name() << std::endl;
return(0); };
I know this is incorrect because the pairs will be replaced by the key_type metafunction itself.
If I add ::type to the end of key_type
, _> the compiler complains that no ::first member exists:
What's the right way to do this?
Use an algorithm like transform that _computes_ the new values rather
than simply replacing them with a constant value:
template <class Seq>
struct replaceit
: transform<
Seq
, if_<
is_base_and_derived
Furthermore, is there a better way to identify pairs in replace_if than deriving from a special class? All I can think of is writing a predicate class and specializing it for mpl::pair. Seems like there should be an easier way.
Why? That seems like a pretty darned good approach to me. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
David Abrahams wrote:
{ replaceit< vector< charm
You should be seeing a syntax error right here.
:) I'll admit I had to patch something up in the e-mail. Obviously I mistyped.
What's the right way to do this?
Use an algorithm like transform that _computes_ the new values rather than simply replacing them with a constant value:
Ok, thanks. I have to read some more to better understand which algorithms operate on constants and which invoke metafunctions. I should have been clued in by the name to look up the STL version.
Furthermore, is there a better way to identify pairs in replace_if than deriving from a special class? All I can think of is writing a predicate class and specializing it for mpl::pair. Seems like there should be an easier way.
Why? That seems like a pretty darned good approach to me.
I guess it didn't feel like the "mpl way" to me. I remember back when MPL was first being discussed that the STL-ness of it was compared to the pattern-matching approach of Loki. I was a doubter about the STL-ness but now that I've used it some I'm warming up to it. :) Thanks again. I'm slowly climbing the curve... -Dave
participants (2)
-
David Abrahams
-
David Greene