C++ Logo


Advanced search

Subject: Re: [std-proposals] Proposal of Contract Primitives (DRAFT 1)
From: Tony V E (tvaneerd_at_[hidden])
Date: 2019-08-06 19:32:02

The radius of a circle is intrinsic - it defines the circle. 
The position of a circle is often treated as a property of the circle, but is actually a property of the circle *in relation to* its surroundings. It should be considered extrinsic to the circle. 
(should two circles of the same size be considered equal, etc...)

Prologue and epilogue seems to be a relationship between the function and where it is called, not a property of the function itself. ‚ÄéMost functions don't have restrictions about where they are called (like 'can only be called directly from main' or 'only as part of static initialization'). We do have constexpr functions, but they have conditions intrinsic to the function that are allowed or not (although we are removing most of those limitations). Whereas constinit is a property of the call site not the function.

Intrinsic vs extrinsic is a standard question I ask about most design issues. 

I agree 'access to return value'  would be a differentiation, but that might be better captured by std::expression instead of epilogue. Or be intrinsic to some pre: cond() syntax - as return value is intrinsic to the callsite, not the cond(). 

Sent from my BlackBerry portable Babbage Device
From: Andrew Tomazos
Sent: Tuesday, August 6, 2019 8:14 PM
To: Tony V E
Cc: sotrdg sotrdg via Std-Proposals
Subject: Re: [std-proposals] Proposal of Contract Primitives (DRAFT 1)

On Wed, Aug 7, 2019 at 2:29 AM Tony V E <tvaneerd@gmail.com> wrote:

Why is prolouge/epilogue a property of the function, instead of where it is called from?


    prolouge precond(...expr...);
    epilogue postcond(...expr...);

    f() precond(x > 0) postcond(z < 0);


    void cond(...expr...);

    f() pre: cond(x > 0), post: cond(z < 0);

Is prologue/epilogue an *intrinsic* property of the function it is tagged to, or an *extrinsic* property of where it is to be used?
I think it is extrinsic.
I'm not sure I know the difference between an intrinsic property and an extrinsic property, but two points:

1. Given your function cond I can write two one-line functions:

    prologue void inline precond(bool condition) { cond(condition); }
    epilogue void inline postcond(bool condition) { cond(condition); }

To get the same functionality.

The reverse is not so.  Given two distinct functions precond and postcond, I can not write a single cond function that wraps them.

You may want to do different things in a precond and postcond function (including, say, putting in the error message "precondition violation" or "postcondition violation" respectively)

2. We may want to provide distinct functionality to prologue functions and epilogue functions later.  For example, I could imagine a future extension that allows access to the return value within epilogue function definitions but not within prologue function definitions.

On Tue, Aug 6, 2019 at 4:19 AM Andrew Tomazos via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
Please find attached DRAFT 1 of:

    Proposal of Contract Primitives

Feedback appreciated.

Std-Proposals mailing list

Be seeing you,

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups