Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!gegeweb.org!news.enother.com!news.glorb.com!news2.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 14 Apr 2011 17:20:01 -0500 Return-Path: Sender: std-cpp-request@vandevoorde.com Approved: austern@google.com Message-ID: <90p22kFeeiU17@mid.individual.net> Newsgroups: comp.std.c++ From: Ian Collins Subject: Re: valarray computed assignment - arrays of different sizes Organization: unknown References: <90jvqmFhg6U15@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Original-Date: Fri, 15 Apr 2011 08:00:20 +1200 X-Submission-Address: std-c++-submit@vandevoorde.com To: undisclosed-recipients:; Date: Thu, 14 Apr 2011 17:18:51 CST Lines: 54 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-UZknHKg6cNI5oJDFVM8RQmWKFEYliN0Ktpdw7LpJaeMp9HODT4oz7xAcJ6fa6u36cyhD4lslkp4AEti!weag6X7Vo9WytozRfk/jso3DfC6EKRAQdEHe54eJGnNqu81oEYPwgUEq7mY= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3331 Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:104 On 04/15/11 07:12 AM, Daniel Kr=FCgler wrote: > > On 2011-04-13 21:06, Ian Collins wrote: > >> >> In section 26.6.2.7 valarray computed assignment, paragraph 3 states >> >> "If the array and the argument array do not have the same length, the >> behavior is undefined." >> >> Is there a good reason why equal length should not be a requirement? >> >> The same applies to binary operators (26.6.3.1) and logical operators >> (26.6.3.2). >> > > For me the current state has good reasons. Compound assignments or > binary operations are semantically elementwise operations, e.g. > operator+= is supposed to add to the i-th element of the destination th= e > i-th element of the source. If the array length are different it is > unclear what the semantic of the operation would be. It is possible to > invent some semantics (e.g. consider the value of the missing element as > T(0)), but I consider this decision as arguable and not necessarily > natural or intuitive (you also need to answer the question, whether the > initial or whether the final elements are considered as null values). > Exactly, so why keep yet another instance of UB in the standard? The programmer can't assume one implementation's design decisions are portable. Let me rephrase: What harm would be done if equal length were a requirement= ? This situation is very different from an unconditional assignment e.g. > for the move/copy-assignment: Here the semantics is a full replacement > of the destination by the source, there is no possible interpretation > problem in regard to not matching elements, because the elements are > fully replaced. > It is different, but I ask again, why leave the ambiguity in the standard? -- Ian Collins [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]