Metaprogamming question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Metaprogamming question

John M. Dlugosz
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?

Thanks everyone,
--John


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Metaprogamming question

Joaquin M LópezMuñoz
El 08/07/2011 12:17, John M. Dlugosz escribió:

> 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?

Using a boost::mpl::map?

http://www.boost.org/libs/mpl/doc/refmanual/map.html

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at.
http://www.tid.es/ES/PAGINAS/disclaimer.aspx
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Metaprogamming question

Mathias Gaunard-2
On 08/07/2011 12:30, [hidden email] wrote:

>> So, how do I write the metafunction that maps the type to the tag?
>
> Using a boost::mpl::map?
>
> http://www.boost.org/libs/mpl/doc/refmanual/map.html

Or explicit specialization.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Metaprogamming question

Nat Goodspeed-2
In reply to this post by John M. Dlugosz
On Jul 8, 2011, at 6:17 AM, "John M. Dlugosz" <[hidden email]> wrote:

> Can I use something like enable_if to tell if a class has a push_back or resize function?

Isn't that what the Type Traits Introspection library (currently under review) does?
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Metaprogamming question

Edward Diener-3
On 7/8/2011 8:17 PM, Nat Goodspeed wrote:
> On Jul 8, 2011, at 6:17 AM, "John M. Dlugosz"<[hidden email]>  wrote:
>
>> Can I use something like enable_if to tell if a class has a push_back or resize function?
>
> Isn't that what the Type Traits Introspection library (currently under review) does?
>>

Yes, precisely. As long as you know the signature of the member function
or static member function for which you are looking, TTI can tell you at
compile-time whether it exists or not.

I encourage you to look at the library and give your comments as well as
review the library.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users