Boost logo

Boost :

Subject: Re: [boost] Suggestions for TMP/function introspection problem?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-11-07 20:38:14


AMDG

On 11/07/2018 01:18 PM, Hans Dembinski via Boost wrote:
>
> I am trying to figure out how to solve an introspection problem since a few
> days, and I am not making progress. I could use some help, it is for
> boost.histogram. Maybe what I want is not possible...
>

I don't know what you need this for, but
I would recommend reconsidering why you
need this in the first place.

> Here is my problem. I have some classes A, B, ... which have some
> overloaded methods, let's call them `foo`.
>
> struct A {
> void foo(int, char);
> void foo(bool, int, char);
> };
>
> struct B {
> void foo(double);
> void foo(bool, double);
> };
>
> I need a way to detect how many arguments the shorter methods has. If the
> shorter method is foo(Ts...), the longer method is always (bool, Ts...).
> This is guaranteed. I do not know what Ts... is, it can be anything.
>

What if Ts... has a bool as the first item?

> I cannot use boost::callable_traits, because an overloaded member function
> cannot be fetched by name
>
> using t = boost::callable_traits::args_t<decltype(&A::foo)>; // fails,
> overload is ambiguous
>
> Can't I match the member function with a template of the form
> something(bool, Ts...) somehow?
>

Like this?

template<class R, class C, class... T>
constexpr int arity_impl(R (C::*)(bool, T...))
{ return sizeof...(T); }

template<int N>
struct int_ {};

struct Tester {
    void fun(double);
    void fun(bool, double);
};

int main() {
    int_<arity_impl(&Tester::fun)> x;
}

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk