-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Initializer Lists within Block initialization default to BLOCK! #1
Comments
Talking to myself again? I have a habit of doing this.
It might be. But bear in mind that punning on As it turns out, there is a technical reason not to do it also. The way AnyBlock uses variadic construction to get a memory-efficient std::array under the hood (vs. a std::vector) won't work with it. Here's the mumbo-jumbo explaining why, via Nicol Bolas:
I've done experiments showing it is possible to get the behavior if you move to an initializer_list based implementation. But that would take away the variadic construction that sets up the std::array, which is 100% just a C-style array under the hood. So that would allocate a vector on every such construction. Not that expensive, but a little bit of an expense. For the questionable payoff of ambiguous-looking code. If you want to save on typing there's lots of ways to get that:
|
Reopening this issue for discussion. @Morwenn pointed out that the technical underpinnings of initializer_list were actually an array...and you could effectively get at the data for that array as a pointer from the iterator. So basically all the std::array work was not necessary. This seems to reopen the door to this. I talked myself out of it partially from an implementation point of view, but maybe it should be rethought--so that if we can do it, should we? |
To truly close this issue out, @hostilefork needs to go back to the code review question and fix it up to correct potential future misunderstandings for others.
Old link from source about performance gap of vector vs. array:
|
So, the problem should definitely be solved with the pull request #51 (as explained in its description). To sum up just in case we need to check again in the future:
The global behaviour of untyped curly braces can then be trivially defined for every type deriving from |
So what's keeping this an open issue for now is that while the method is working for constructors, it's not working for variadic functions. So:
Won't make a block out of {2, 3} even if you use BlockLoadable. @Morwenn says this is likely a technical limitation of constructors that take initializer lists vs. variadic functions that do. It may warrant a StackOverflow question for a canon answer. If it turns out to be true that you can't do it, then it can either be left alone or some trick to make runtime calls somehow rig around internally with a class constructed on each call, so something like: runtime {1, {2, 3}, 4}; Exactly what that would involve is not known. But this is a good thing to consider as the runtime/engine level goes under review. |
The thing is that the only way to get as many elements as we want in
With such a anguage extension (proposed, but I am not even sure that it will make it to C++17), the compiler would know that every parameter is to be deduced as a |
Detailed set up and build instructions for Linux
Right now you have to write:
Using a std::initializer_list, this could default to the behavior of assuming "brace means block". Then you could write:
It's a little bit questionable because
{
isn't really a[
, and there's not necessarily any real reason why a BLOCK! should get this special treatment over PAREN! or PATH!. But it might be cute.The text was updated successfully, but these errors were encountered: