From: Christian H. <chh...@gm...> - 2007-06-11 17:38:19
|
Hi Dean, I think the MS compiler is right. Defining a variable extern means it has external linkage. We shouldn't try to be "too smart" in fooling the compiler. This code can break with every new compiler version. I don't see it as a problem when using parenthesis. boost::gil does something similar channel_t& c = get_color( pixel, red_t() ); But if you don't like that then there are other ways, like using an enum ( I know it's old school ) or use total template specialization. I'm sure there are other ways. Christian On 6/11/07, Dean Michael Berris <mik...@gm...> wrote: > Hi Christian, > > On 6/11/07, Christian Henning <chh...@gm...> wrote: > > > > And there were no problems. Does that makes sense to you? > > > > Two issues here: > > 1. The unit test is a specification on how the interface is meant to > be. Although your solution would work, the readability of additional > parentheses aren't very appealing to me. The unit test is an example > in itself of how the interface *should* look like and I'd like > to_upper_ (and other future transformations to be implemented) to not > have the extra parentheses. > > msg << transform(to_upper_, source_) ; > > Reads better IMO than > > msg << transform(to_upper_(), source_()) ; > > The same way > > boost::bind(&function, _1) ; > > Reads better than > > boost::bind(&function, _1()) ; > > 2. The premium is put on readability and extensibility. The transform > template function is meant to extend to more than just a pair of > parameters. For flexibility's sake, see the example below: > > msg << transform(to_upper_, source_ & destination_) > << transform(headers_, to_upper_ & trim_) > ; > > With template metaprogramming, operator& can be overloaded to produce > a composite selector and composite transformations. This gives > 'transform' a flexible enough interface which allows: > > msg << transform(to_upper_, source_) << transform(source_, to_upper_) ; > > Of course, with the help of template metaprogramming. In this regard, > having extra parentheses doesn't help with readability. > > NOTE: This is the direction of the transformation interface (and other > interfaces to the message type in general), to leverage on > compile-time meta-programming to produce readable and flexible > interfaces. > > The above are the two rationale's for why I opted for 'extern > to_upper_placeholder to_upper_' instead of making it a typedef in the > first place. It just so happened that my first iteration > implementation hit a snag (which I sure hope would be temporary). > > So the real question now would be (assuming it works with GCC) how we > can allow the above parentheses-less while keeping MSVC and other > compilers happy? > > -- > Dean Michael C. Berris > http://cplusplus-soup.blogspot.com/ > mikhailberis AT gmail DOT com > +63 928 7291459 > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Cpp-netlib-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel > |