|
Boost : |
Subject: Re: [boost] [introspection] if a function is not public
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-07-01 10:30:00
On Thu, Jun 30, 2011 at 6:53 PM, Edward Diener <eldiener_at_[hidden]> wrote:
> This is off the top of my head but...
>
> It might be possible by declaring a friend class which does the
> introspection ala my TTI generated classes. If the friend class can find the
> function but a non-friend class can not find the function, then one knows
> that the function is not public. Similarly if one could have an
> introspection class derived from the actual class being introspected and
> find the function while not finding it otherwise, one knows it is a
> protected function. Whether either of these things can actually be done by
> TTI I would have to take a much closer look at eventually. Of course in any
> case one would have to know that the actual function exists in the class
> else not finding the function in any situation could mean it does not exist
> at all.
This sounds interesting... when I have time I will play with
friendship and SFINAE...
> I know that Joel Falcou, who is the Review Manager for my TTI libary, played
> around with 'friend' in introspecting class data, but I never followed up
> looking at his idea when doing TTI. Your query gives me something to think
> about for TTI, although I think the actual usefulness might be pretty small
> even if it could be done even if you have found a use for it.
I agree. The use case I have for it is very domain specific and I
don't think many other people would find this useful. Anyways, I will
explain my use case.
I need this feature because in Contract Programming class invariants
should be checked only for public functions while they should not be
checked by protected and private functions (see for example N1962). So
I need to program something like "if this member function is public
check the class invariants, else don't check". I actually only need to
program this at run-time but I had to go all the way and add the
public keyword to the function preprocessor signature so I could
program this up at the pp level with a macro like:
PP_IS_PUBLIC( public void (f) ( int x ) ) // expand to 1
PP_IS_PUBLIC( private void (f) ( int x ) ) // expand to 0
If there was a way to detect the function access level at compile-time
(or even run-time) then I would not need to use pp-metaprogramming to
do this check and I could simplify the above syntax by not requiring
to specify the member function access level (which kind of look ugly).
> BTW the review of TTI begins tomorrow, and any relevant idea is welcome even
> if I choose to not actually try to implement it ( it may also be impossible
> ).
I'll take a close look to TTI.
Thanks.
--Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk