--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
The whole situation arises when trying to implement a small_vector that supports for example small_vector<const int> as type.
Suppose I can use std::array<T, N> or T[N] for implementing the small vector storage (which is true for LiteralTypes). I can construct a std::array<const int, N> if I use a braced-init-list directly.
But if I have it as a data-member of some other type A, there is no way for any of A constructors to forward a braced-init-list without screwing up the distinction between {} and () constructors.
All good points. FWIW I am dealing with Case 1: the capacity has a compile-time maximum.I am using `std::aligned_storage` except for `LiteralTypes`, for which I am using either a C-array or a std::array.
This allows using the whole vector API withing C++14 constexpr functions when the types are LiteralTypes, but comes at the cost of value initializing the elements at run-time. Since the vectors are small an on the stack, I hope that the compiler is smart enough to detect that I value initialization is zeroing the memory just to replace it with some other values afterwards, but I haven't measured.
For using aligned_storage one fundamentally needs 3 language features: placement new, reinterpret cast, and explicit destructor calls, none of which can be used within constexpr functions. I don't think these will be available soon, so for such a type, constexpr support comes with a run-time cost.
No that would be super confusing, please don't do that. Especially not the latter. You are mixing grammar production that parse the thing with the name of the thing. If I recall correctly, {...} is parsed by a production called braced-init-list. However the name for this construct is "initializer list":
"List-initialization is initialization of an object or reference from a braced-init-list. Such an initializer is called an initializer list".
You find similar examples in clause 8 with the grammar term "/initializer/" and the name "initializer". The distinction allows to talk aout the thing more abstractly. So a "= {...}" has an initializer list as initializer. But not a /braced-init-list/ as /initializer/.
braced-init-list:
{ initializer-list , opt }
{ }
On 2016–03–11, at 9:26 PM, Gonzalo BG <gonza...@gmail.com> wrote:The following program is not valid C++:
#include <initializer_list>int main() {constexpr std::initializer_list<int> il{1, 2, 3};constexpr int a[3]{il};return 0;}
Is there a way to _directly_ initialize a C-array from an initializer list?
So in the standard we have initializer_list, initializer-list, and initializer list. Three different things. How could anyone find that confusing?