|
|
Up |
  |
Author: mcostalbamcostalba Date: Apr 30, 2008 08:43
Hi all,
I have a problem.
What is the best way to get a type TC from a type T where
T is int(foo::*)(char)
and
TC is int(foo::*)(char) const
I have tried
typdef T const TC
but with no success.
Thanks
Marco
|
| |
|
| | 12 Comments |
|
  |
Author: nickf3nickf3 Date: Apr 30, 2008 15:11
On Apr 30, 12:38 pm, mcostalba gmail.com> wrote:
> Hi all,
>
> I have a problem.
>
> What is the best way to get a type TC from a type T where
>
> T is int(foo::*)(char)
>
> and
>
> TC is int(foo::*)(char) const
>
> I have tried
>
> typdef T const TC
>
> but with no success.
>
> Thanks ...
|
| Show full article (0.76Kb) |
|
| | no comments |
|
  |
Author: smolenskysmolensky Date: Apr 30, 2008 20:19
On Apr 30, 12:38 pm, mcostalba gmail.com> wrote:
> Hi all,
>
> I have a problem.
>
> What is the best way to get a type TC from a type T where
>
> T is int(foo::*)(char)
>
> and
>
> TC is int(foo::*)(char) const
>
> I have tried
>
> typdef T const TC
>
> but with no success.
>
|
| Show full article (1.22Kb) |
| no comments |
|
  |
Author: Devdatt LadDevdatt Lad Date: Apr 30, 2008 20:19
> What is the best way to get a type TC from a type T where
>
> T is int(foo::*)(char)
> and
> TC is int(foo::*)(char) const
These two types are completely different. A better way to understand the
meaning of these types is:
T ==> int (foo::*)(foo obj, char c)
TC ==> int (foo::*)(const foo obj, char c)
Thus, it is not the member function pointer which is const or non-const. It
is actually an argument of the member function that differs in const-ness.
This cannot be done with a static_cast or a const_cast.
You can use a reinterpret_cast to do this.
T x = &foo::abc;
TC y = reinterpret_cast(x);
but be careful when using the result of reinterpret_cast.
Hope this helps,
Devdatt
|
| Show full article (0.85Kb) |
| no comments |
|
  |
Author: Greg HerlihyGreg Herlihy Date: Apr 30, 2008 20:28
On Apr 30, 9:38 am, mcostalba gmail.com> wrote:
> I have a problem.
>
> What is the best way to get a type TC from a type T where
>
> T is int(foo::*)(char)
>
> and
>
> TC is int(foo::*)(char) const
I'm assuming that you want to "synthesize" a member function pointer
type for a const class method - given a member function pointer for an
equivalent non-const class method. (Otherwise, it is not possible to
convert actual member pointer instances from one type to the another.)
In order to synthesize the const member function pointer type from the
non-const equivalent, I would declare a "helper" template like so:
// General helper template declared - but not defined
template
struct AddConstToMemberFunctionPtr;
|
| Show full article (1.60Kb) |
| no comments |
|
  |
Author: mcostalbamcostalba Date: May 1, 2008 11:51
On 1 Mag, 06:17, Greg Herlihy mac.com> wrote:
>
> I'm assuming that you want to "synthesize" a member function pointer
> type for a const class method - given a member function pointer for an
> equivalent non-const class method.
Yes, this is similar to what I have to do, actually I have to do the
contrary: detect pointer to const member functions.
|
| Show full article (2.32Kb) |
| no comments |
|
  |
Author: Roman.PerepelitsaRoman.Perepelitsa Date: May 5, 2008 05:48
On 1 May, 21:43, mcostalba gmail.com> wrote:
> I have to detect if a functor type Fun has a given signature Sig, i.e.
> if Fun::operator() has a signature Sig
|
| |
| no comments |
|
  |
Author: mcostalbamcostalba Date: May 5, 2008 23:00
On 5 Mag, 15:09, "Roman.Perepeli...@ gmail.com"
gmail.com> wrote:
> On 1 May, 21:43, mcostalba gmail.com> wrote:
>
>> I have to detect if a functor type Fun has a given signature Sig, i.e.
>> if Fun::operator() has a signature Sig
Thanks Roman for your link.
Actually there are some good ideas in that implementation and I will
try to borrow a few of them...
Unfortunatly it does not fit the bill 100%%, indeed:
|
| Show full article (1.86Kb) |
| no comments |
|
  |
Author: Roman.PerepelitsaRoman.Perepelitsa Date: May 6, 2008 06:30
On 6 May, 08:57, mcostalba gmail.com> wrote:
> Thanks Roman for your link.
>
> Actually there are some good ideas in that implementation and I will
> try to borrow a few of them...
>
> Unfortunatly it does not fit the bill 100%%, indeed:
>
> - Implicit argument type conversion should be avoided in my context,
> due to some ambiguites that can arise when there is more then one
> candidate among the overload set. So signature matching would be ok to
> be strict.
> - It seems you have to add a specialization for each argument arity,
> in my implementation I would try to avoid this.
Yes, you can use variadic templates (if your compiler supports then)
or boost::preprocessor to automate generation of specializations.
|
| Show full article (1.79Kb) |
| no comments |
|
  |
Author: mcostalbamcostalba Date: May 6, 2008 11:14
On 6 Mag, 16:21, "Roman.Perepeli...@ gmail.com"
gmail.com> wrote:
I have quickly checked the link and it surely deserves a deeper read
when I found a bit of time.
Anyhow here is my much simpler solution...so simple that is probably
broken in some way, but I cannot find where:
/* Check if a function/functor Fun has a given signature Sig */
template
struct is_compatible
{
typedef typename boost::remove_pointer::type F;
|
| Show full article (2.64Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|