Boost logo

Boost :

Subject: Re: [boost] [Review] TTI
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-07-29 09:09:17


On 7/27/2011 12:51 PM, Noah Roberts wrote:
> On 7/26/2011 2:25 PM, Edward Diener wrote:
>> On 7/26/2011 5:03 PM, Jeffrey Lee Hellrung, Jr. wrote:
>>> On Tue, Jul 26, 2011 at 1:19 PM, Noah
>>> Roberts<roberts.noah_at_[hidden]>wrote:
>>> [...]
>>>
>>>> One thing that I think is missing is the option to check for a named
>>>> callable within a type. For example, one might want to use enable_if
>>>> style
>>>> concept checking. So long as a type has function 'xxx' that takes
>>>> arguments
>>>> of type x,y,and z, and returns something convertible to type A, the
>>>> concept
>>>> is obeyed. I don't believe this can be done with C++03, but with
>>>> C++1X I
>>>> was able to do something using decltype.
>>>>
>>> [...]
>>>
>>> Actually, you can approximate it pretty well in C++03 (using
>>> derivation and
>>> using tricks) to the point that I think it will work pretty much as you
>>> expect except for nullary member functions, where your queries must be
>>> more
>>> restrictive. This is a useful query, but I believe Edward has decided
>>> it to
>>> be outside the scope of TTI.
>>
>> I am not sure what the OP means by 'named callable". If it can be
>> introspected within the type I can consider whether it can be done or
>> not.
>
> What I mean by "callable" is that the expression may not be just a
> function call but could also be a template instantiation. For example:
>
> Concept C
> z = c.fun(x) | x is an int | result convertible to double
>
> This class obeys:
>
> struct class_a
> {
> double fun(int);
> };

This can be determined by TTI.

>
> As does this one:
>
> struct class_b
> {
> template < typename T >
> double fun(T);
> };

This is actually doable in TTI but I dropped the implementation because
of compiler bugs in gcc and vc++ ( clang works ). See the section in the
documentation called "Introspecting Function Templates".

>
> As does this one:
>
> struct class_c
> {
> template < typename T >
> converts_to_double_type fun(T);
> };

See above. My experimental implementation in TTI might actually work
with a converted return value, but offhand I do not think so.

>
> And this:
>
> struct class_d
> {
> double fun(has_implicit_int_constructor);
> };

Jeffrey Hellrung has shown me some code and techniques I will adapt for
TTI which could do this.

>
> etc...
>
> The question being asked here is, can I call something called X within
> type T that accepts parameters x,y,z and returns something I can assign
> to type A?
>
> Answering this question is often more interesting than the question,
> "Does type T have function X with signature Y?" It also cannot be
> correctly answered with such a check because it could be implemented by
> template, a function that has default arguments, or a function that
> takes other types but they are convertible.

It does seem reasonable to ask that question. I will work on the idea
you mention of being able to specify any callable in TTI.

>
> I would consider this within the scope of "introspection", but I can see
> why it might be omitted for a future version or something.

Eddie


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