|
Boost : |
From: Eric Friedman (ebf_at_[hidden])
Date: 2002-08-06 01:05:36
See attached for my (partially successful) attempt, which uses
mpl::max_element and my is_better_conversion<From,To1,To2> metafunction.
The problem comes in that C++ does not distinguish, for example, in the
quality of the following conversions:
int -> char // this is a valid conversion...
int -> float // ...but this is equally valid
Since overload resolution does not tell which of the above is the better
conversion, it is not possible to yield a reasonable result from
following:
best_conversion< int, mpl::list<float,char> >::type // ambiguous: char
or float?
Please tell me if another approach might work.
Thanks,
Eric
P.S. For perspective on the problem, what I am currently doing with
Boost.Variant is choosing the unambiguously-best conversion *if
available*, else failing a static assert (i.e. if the conversion is
ambiguous or does not exist). I'm not sure what would be the best way to
encapsulate this kind of behavior in a best_conversion metafunction,
however.
-----Original Message-----
From: Alexander Nasonov [mailto:alnsn_at_[hidden]]
Sent: Monday, August 05, 2002 10:25 AM
To: boost_at_[hidden]
Subject: [boost] best_conversion
Some time ago Eric Friedman posted a message 'is_better_conversion':
http://aspn.activestate.com/ASPN/Mail/Message/1264796
I posted reply with solution but I have no free time to polish it:
http://aspn.activestate.com/ASPN/Mail/Message/1274580
But I would like to. Ideally, I would like to see something like this:
typedef best_conversion<int,
TYPELIST_3(char, float, int)>::type best_for_int;
// best_for_int should be best conversion to int
// among char, float and int
typedef best_conversions<int,
TYPELIST_3(char, float, void *)>::list all_best_for_int;
// all_best_for_int should be a typelist of types that have
// best conversions to int among char, float and void *
Any ideas?
-- Best regards, Alexander Nasonov Fraunhofer Gesellschaft
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk