standardese icon indicating copy to clipboard operation
standardese copied to clipboard

Possibly support N4381-style function objects?

Open timsong-cpp opened this issue 9 years ago • 9 comments

See N4381. These are global function objects that should be documented like functions, rather than objects. They are used extensively in range-v3.

timsong-cpp avatar Nov 29 '16 20:11 timsong-cpp

You can already override the entire synopsis of an entity with the \synopsis command, I plan on adding a command on changing the entity type name for the header as well.

With it you can completely override what an entity is.

foonathan avatar Nov 29 '16 21:11 foonathan

This can split an entity into several, though. Consider:

struct foo_fn {
    // \requires XXXX
    template<class A, class B>
    void operator()(const A&, const B&) const; 

    // \requires YYYY
    // \returns ZZZZ
    template<class A, class B, class C>
    int operator()(const A&, const B&, const C&) const;
};

// \n4381_magic
constexpr inline foo_fn foo{};

Ideally the generated documentation should be as if for

// \requires XXXX
template<class A, class B>
void foo(const A&, const B&);

// \requires YYYY
// \returns ZZZZ
template<class A, class B, class C>
int foo(const A&, const B&, const C&);

timsong-cpp avatar Nov 29 '16 21:11 timsong-cpp

I definitely have plans for such advanced output manipulation, but this will probably take some time as I have other things prioritized.

foonathan avatar Nov 29 '16 21:11 foonathan

@timsong-cpp The function object and the functions are not equivalent. So a reference documentation shouldn't do that.

The intent of the inline function object is to disable ADL when found in the first phase overload resolution lookup.

I believe that when we will have overload set (P0119) we could do the following

namespace xxx {
// \requires XXXX
template<class A, class B>
void foo(const A&, const B&);

// \requires YYYY
// \returns ZZZZ
template<class A, class B, class C>
int foo(const A&, const B&, const C&);
}
auto foo = xxx::foo;

Might the generated documentation will be ideal for you in this case?

viboes avatar Nov 30 '16 06:11 viboes

The function object and the functions are not equivalent. So a reference documentation shouldn't do that.

I would rather have a blanket introductory paragraph explaining that they are actually function objects, but depicted as functions for simplicity and ease of understanding. That's far better than documenting them as "a constexpr function object of unspecified type that has the following overloaded function call operators".

timsong-cpp avatar Nov 30 '16 07:11 timsong-cpp

"Standardese" could provide whatever features the author consider pertinent. Could you complete your example with reference to your introductory paragraph?

Would you prefer the standard Range TS be defined the way you are suggesting?

viboes avatar Nov 30 '16 23:11 viboes

"The standard Range TS" is a different beast because it uses this only for actual customization points, where you need to specify a complicated set of lookup rules which is better done in words than code.

OTOH, the range-v3 use of this thing extends to plain algorithms and the like, whose counterpart is function templates in the range TS. This kind of uses is where a transformation like this is useful (the only reason I made this suggestion is because Eric Niebler suggested that I do it a few months ago...)

timsong-cpp avatar Nov 30 '16 23:11 timsong-cpp

Ok. So you are not talking of the customization points then.

If this ticket don't pretend to take care of N4381-style customization point objects anymore, how would Standardese document such function objects?

Even for algorithms, I believe it is needed to document that the user is working with function objects as they are usable as HOF and be passed as arguments to other functions.

viboes avatar Dec 01 '16 22:12 viboes

If this ticket don't pretend to take care of N4381-style customization point objects anymore, how would Standardese document such function objects?

Actual customization point objects with complicated overload resolution logic should probably be documented similar to the way they are documented in the ranges TS: "foo is a customization point object. The effect of calling foo(E) is as follows: x.foo() if that expression is well-formed; otherwise foo(x) with ADL, etc., etc." Presumably, this will have to be hand-written. I can't imagine automatically generating this stuff.

Even for algorithms, I believe it is needed to document that the user is working with function objects as they are usable as HOF and be passed as arguments to other functions.

Yes, and that can go into the hypothetical introductory paragraph somewhere.

timsong-cpp avatar Dec 01 '16 22:12 timsong-cpp