Em dom 20 abr 2014, às 00:08:44, Andrew Tomazos escreveu:We propose the following two new standard conversions:
1. A value of type "derived-declarator-type-list array of N T" of value
category VC can be converted to a value of type
"derived-declarator-type-list std::array<T,N>" of value category VC.
2. A value of type "derived-declarator-type-list std::array<T,N>" of
value category VC can be converted to a value of type
"derived-declarator-type-list array of N T" of value category VC.
Can you specify this in such a way I can do the same for QVarLengthArray?
I.e., please give me the underlying tools instead of writing "std::array" in
the spec.
I think std::array_view is supposed to be the general solution, no?
These conversions seem way more trouble than they’re worth, given that. For one thing, user specializations would have to be disallowed.
By the way, what is derived-declarator-type-list? It seems to be an occasionally used meta-variable, but it has no single definition per se. Perhaps it was a grammar production in pre-standard drafts.
On Monday, April 21, 2014 5:50:34 AM UTC+2, David Krauss wrote:I think std::array_view is supposed to be the general solution, no?The general solution to what? std::string_view and std::array_view provide a non-owning reference type to a subsequence of a string-like or array-like container. It isn't clear what relevance they have to this proposal. The purpose of this proposal is to bring parity between built-in array types and std::array. It is a kind of simplification.
These conversions seem way more trouble than they’re worth, given that. For one thing, user specializations would have to be disallowed.User specializations of what? And why would they have to be disallowed? And what are the other things apart from this "one thing”?
By the way, what is derived-declarator-type-list? It seems to be an occasionally used meta-variable, but it has no single definition per se. Perhaps it was a grammar production in pre-standard drafts.It just means some (possibly empty) prefix of compound type declarators. For example "reference to const pointer to":int (* const & x) [10] = ...;std::array<int, 10>* const & y = x; // ok
We propose the following two new standard conversions:1. A value of type "derived-declarator-type-list array of N T" of value category VC can be converted to a value of type "derived-declarator-type-list std::array<T,N>" of value category VC.2. A value of type "derived-declarator-type-list std::array<T,N>" of value category VC can be converted to a value of type "derived-declarator-type-list array of N T" of value category VC.
I'd really like to just see a shorthand for declaring std::array objects, with compiler warnings enabled for declaring now depreciated C arrays.
I meant that they would be depreciated after the new syntax becomes available.
You don't need a language extension to simplify it:
#include <type_traits>
#include <array>
template<typename T>
class convert_array {
public:
using type = T;
};
template<typename T, size_t N>
class convert_array<T[N]>
{
public:
using type = std::array<typename convert_array<T>::type, N>;
};
template<typename T>
using array = typename convert_array<T>::type;
int main()
{
array<int[2][3]> matrix3d;
matrix3d[1][2] = 42;
return 0;
}
Bye,
Nicola
Other than maintaining C compatibility, the ugly syntax of std::array, and unbounded initialization. Can you name one reason why someone should prefer to still use C arrays?
Why should we continue to suggest that programmers use C arrays if we have a replacement that is better on all accounts except for a few backwards compatible edge cases?
Its already terrible that we have 2 different fixed size array types and we have to teach new programmers the differences between them. Even worse that the most natural syntax is for the one that should be avoided. This kind of legacy cruft is what makes people run screaming to other languages.
I'd really like to just see a shorthand for declaring std::array objects, with compiler warnings enabled for declaring now depreciated C arrays. C arrays with their pointer decaying behavior are really annoying to use and have a lot of pitfalls. Arrays should be separate types with value semantics like everything else in C++. The only use I could see for C array is C compatibility.
std::array<std::array<int, 5>, 10> a; is ugly as hell, its really the only reason I still use C arrays sometimes.
Some possibilities for syntax:
Single dimension arrays with known size
int x[{5}];
int x[[5]]; //maybe this clashes with attribute syntax?
int[5] x;
On 23 April 2014 15:26, Matthew Fioravante <fmatth...@gmail.com> wrote:
Other than maintaining C compatibility, the ugly syntax of std::array, and unbounded initialization. Can you name one reason why someone should prefer to still use C arrays?Backwards compatibility. Why should I change millions of lines of working code just because *you* want to deprecate this?
Why should we continue to suggest that programmers use C arrays if we have a replacement that is better on all accounts except for a few backwards compatible edge cases?Who says we should suggest programmers use C arrays? Quit making straw man arguments.
Its already terrible that we have 2 different fixed size array types and we have to teach new programmers the differences between them. Even worse that the most natural syntax is for the one that should be avoided. This kind of legacy cruft is what makes people run screaming to other languages.
"legacy" is a two-edged sword. It's a major reason people move to C++, and a major reason for many of the whines. I fail to see any evidence that gratuitously breaking backwards compatibility will *retain* C++ developers.
If the C++ community generally agrees that std::array is a better construct than C arrays, why shouldn't they find ways to encourage developers to adopt the new style?
Why should we continue to suggest that programmers use C arrays if we have a replacement that is better on all accounts except for a few backwards compatible edge cases?Who says we should suggest programmers use C arrays? Quit making straw man arguments.
Throwing a compiler warning is a great way to suggest someone not use something.
Not doing so makes it seem like fair game. I don't know about you, but I'd love for my compiler to find all of these instances for me so that I can fix them.
Its already terrible that we have 2 different fixed size array types and we have to teach new programmers the differences between them. Even worse that the most natural syntax is for the one that should be avoided. This kind of legacy cruft is what makes people run screaming to other languages.
"legacy" is a two-edged sword. It's a major reason people move to C++, and a major reason for many of the whines. I fail to see any evidence that gratuitously breaking backwards compatibility will *retain* C++ developers.
Nothing is breaking backwards compatibility. I'm not suggesting C arrays ever get removed from the standard, doing such would break C compatibility.
Standard, but having been identified as a candidate for removal from future revisions."
Instead I'm suggesting discouraging their use to only the cases where they are really needed, which is extern "C" code. Maybe depreciated is too strong a word here, perhaps "discouraged" is better.
Discouraging the use of C arrays from modern C++ would also mean that library writers can stop needing to write special cases for arrays and decaying in their template interfaces.
Couldn't we get most of the way just with some improvements to the library? For example:First, require that std::array representation actually contain an array T[N] (except for N=0), and make this accessible, by changing the data member function to T (&data())[N] (again unless N=0):T (&data())[N];const T (&data() const)[N];
Next, provide a std::make_array function, in four variants:template<class T, size_t N> array<T, N> make_array(T (&)[N]);template<class T, size_t N, class InputIt> array<T, N> make_array(InputIt);template<class T> array<T, 0> make_array();template<class T, class... Ts> array<T, 1 + sizeof...(Ts)> make_array(T, Ts...);
This gives improved interoperability and unknown bound deduction, without having to bless a library type into core.Regards, Ed
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
On Thu, Apr 24, 2014 at 1:04 AM, Edward Catmur <e...@catmur.co.uk> wrote:
Couldn't we get most of the way just with some improvements to the library? For example:First, require that std::array representation actually contain an array T[N] (except for N=0), and make this accessible, by changing the data member function to T (&data())[N] (again unless N=0):T (&data())[N];const T (&data() const)[N];
Next, provide a std::make_array function, in four variants:template<class T, size_t N> array<T, N> make_array(T (&)[N]);template<class T, size_t N, class InputIt> array<T, N> make_array(InputIt);template<class T> array<T, 0> make_array();template<class T, class... Ts> array<T, 1 + sizeof...(Ts)> make_array(T, Ts...);N3824 has already proposed pretty much exactly this. It doesn't have the iterator overload, but that overload is problematic in a lot of ways, and seems superfluous to the goals of array interoperability and bound deduction, so I don't see a need to add it.
On Thursday, 24 April 2014 16:49:46 UTC+1, Geoffrey Romer wrote:On Thu, Apr 24, 2014 at 1:04 AM, Edward Catmur <e...@catmur.co.uk> wrote:
Couldn't we get most of the way just with some improvements to the library? For example:First, require that std::array representation actually contain an array T[N] (except for N=0), and make this accessible, by changing the data member function to T (&data())[N] (again unless N=0):T (&data())[N];const T (&data() const)[N];Wondering - do you know whether this has previously been proposed, or indeed why C++11 std::array does not have array typed member access?
I think std::array_view is supposed to be the general solution, no?