Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7680
| From | Kai-Uwe Bux <jkherciueh@gmx.net> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Templated Casting operators |
| Followup-To | comp.lang.c++ |
| Date | 2011-07-09 13:34 +0200 |
| Organization | University of Bielefeld |
| Message-ID | <iv9ed1$67q$1@hoshi.visyn.net> (permalink) |
| References | (2 earlier) <8edcf612-c6e3-492b-b923-d418a9b8a1ab@s17g2000yqs.googlegroups.com> <iv6cds$a0f$1@hoshi.visyn.net> <8aed9603-26d2-41fb-b197-213bdf90ff99@34g2000yqr.googlegroups.com> <iv7v24$oo9$1@hoshi.visyn.net> <f966f5b5-a173-45f5-b1ea-035ca5977502@n5g2000yqh.googlegroups.com> |
Followups directed to: comp.lang.c++
Narinder wrote:
>>On Jul 8, 11:06 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
>>At the moment, I don't see why.
>
> That is indeed curious.
> However on my issue, I think I am expecting something from C++ .. when
> I obviously should know better, "C++ (101): C++ doesn't dispatch on
> the return type".
That, I think, is not the entire picture. There is clause [14.8.2.3] that
deals with deducing template arguments for templated conversion operators.
Here, the result type desired by the conversion is taken into account.
Howerver, reading that clause, I find it hard to tell whether the deduction
should fail because of ambiguity, whether the const version should be
instantiated, or whether the non-const version should be chosen.
> My question stems from wanting to pass parameters to a function via an
> intermediary which holds references to the values to be passed. And
> this would be done at runtime.
>
> Given :
>
> void f( double x);
>
>
> I want to be able to do:
>
> const double x=3.142;
> intermediary v = x; // so v will hold a
> std::tr1::reference_wrapper<const double>
> f(v); // I suspect gcc will complain because v is unable
> to give up its const ref
> // but as we have seen gcc calls operator
> double&()
Hm, the following compiles:
#include <iostream>
void foo ( double arg ) {
std::cout << arg << "\n";
}
template < typename T >
class reference_wrapper {
T* the_ptr;
public:
typedef T type;
typedef T& reference;
reference_wrapper ( reference t_ref )
: the_ptr ( &t_ref )
{}
operator reference ( void ) {
return ( *the_ptr );
}
reference get ( void ) {
return ( *the_ptr );
}
};
int main ( void ) {
double const pi = 3.14159;
reference_wrapper< double const > x = pi;
foo( x );
}
> My way around this will be to have the user provide a precise boost
> typelist embodying the function signature:
>
> boost::mpl::vector<double>
>
> and use this to dispatch correctly.
Huh?
Best,
Kai-Uwe Bux
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-07 16:34 -0700
Re: Templated Casting operators Alexander Bartolich <alexander.bartolich@gmx.at> - 2011-07-08 00:58 +0000
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-07 22:36 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-08 09:42 +0200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-08 01:16 -0700
Re: Templated Casting operators Ian Collins <ian-news@hotmail.com> - 2011-07-08 20:23 +1200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-08 01:37 -0700
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-08 06:28 -0700
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-08 01:40 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-09 00:06 +0200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-09 03:16 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-09 13:34 +0200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-09 07:18 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-10 01:15 +0200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-09 21:39 -0700
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-09 22:01 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-10 13:43 +0200
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-10 05:55 -0700
Re: Templated Casting operators Narinder <narinder.claire@gmail.com> - 2011-07-10 00:19 -0700
Re: Templated Casting operators Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-10 12:03 +0200
csiph-web