On Friday, March 29, 2013 12:54:18 AM UTC-7, pibara wrote:
2013/3/28 Nicol Bolas
<jmck...@gmail.com>
There's also a fair amount of code out there that doesn't use `main` at all; either they're using `WinMain` or they're being called by some other library that itself uses `main`. You're effectively saying that none of this code can use your helper class.
The standard provides us with 'main' as a logical computational root that we can use as compositional root concerning the authority to construct RAII objects. I propose the above as a facility that uses this logical computational root.
`main` is not a "logical computational root". It isn't even the first code that is required to be executed in a C++ application. It is merely the first code that can assume that all globally-accessible objects have been initialized.
My point is that this method only works if `main` is the root of your application's code. It doesn't have to be, and people for whom this isn't true would be unable to use your code, even if they did have a root.
If a specific compiler or a framework provides an alternative logical computational root that falls outside of the standard and that effectively disables delegation of authority from the standard defined main to the compiler/framework specific computational root, than that would indeed be a problem. Do you have details on how important compilers and frameworks obscure and inhibit the use of the standard defined main for the user?
Well, since that would include a healthy percentage of Windows applications, I'm guessing that it's a non-trivial number. Not to mention every application plugin or DLLs in general.
For compiler builders I would think there should not be much of a problem to allow them to add an extra friend definition to raiicap (for example to winmain) for the version of the standard library that ships with their compiler, but maybe this is a no-go, I don't know.
If a significant number of C++ users would have to invent their own version of `raiicap` in order to use the arbitrary, then what good is it? If a user cannot force `raiicap` to use a specific function, rather than just one form of `main`, then you've limited the use cases for this tools a lot.
I disagree, the user should not be able to force `raiicap` to use an arbitrary function. The creator of a compiler or a framework that inhibits the direct use of main by the user should ideally however be able to do discretionary delegation of its authority to construct arbitrary raiicaps.
So, you want everyone to rewrite their frameworks and such, all to accommodate a type that someone can just rewrite flawlessly in less than a minute?
And of course, that doesn't deal with the C frameworks that call into C++ code, where such delegation is simply impossible.
Depending on the existence of important real-life frameworks that would need this and dependent on the ability of compiler vendors to extend the stl defined types, it may be a good idea for me to look into this and see if I can write an extended proposal that allows for this. In any case its essential that the creator of a library that defines RAII classes should have no notion of the
framework, compiler etc that uses it.
Main is not the center of everyone's universe. Your tool is too restrictive. And C++ doesn't offer a way to generalize it to a user-provided function without employing macros. So I don't think it's a good tool.
Basically discretionary delegation is what makes the tool flexible. User provided functions would brake the model and render the pattern useless. It might however be usefull to change the proposal as to allow the delegation of a full 'root of authority' by framework builders.
There are far better ways to restrict the construction of an object instance to one or more specific functions than this.
Could you elaborate?
The same way you're doing it here, only without an intermediate, dependency-injected object. Make the class's constructors of interest private and make the "one or more specific functions" that can allocate them friends.
That way, it is the writer of the class who gets to decide which functions get to create it.
What business does 'the writer of the class' have 'statically' determining what function gets to create it.
It's their class. The owner of a class has the right to determine who gets to create it. That's what your entire construct relies upon: the owner of the class must use this `raiicap` tag to force users to only create the object if they have authorization to do so.
The only difference is who decides who has that authorization. In your case, it's delegated to some other class. In my case, it's determined on a class-by-class basis. So each class can decide, for themselves, who gets to create them.
My proposal allows the writer of the class to state: "The creator of the 'program' gets to do discretionary delegate the right to create".
"But only if the user has direct, modifiable access to `main`."