🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1969

Pascal-like 'with' statement feasible in C++?

#1969
From: Eugene Radchenko
Date: Thu, 14 Sep 1995 17:28
42 lines
2158 bytes
Hello people!
I would like to hear the opinions on the following problem:
whether it is possible/worthwhile to introduce the analog of Pascal 'with'
statement into C++ ? has someone proposed/considered it?
(IMHO, it is the only one nice Pascal feature (now that bitsets are (soon)
available) amiss from C++. For those not familiar with the topic, here is a
brief (and possibly not quite exact) explanation:
Suppose you have the following declarations:
  type tpair = object
         m,n: integer;
         end;
  var  pairs : array[1..10] of tpair;
then you can write, for instance:
  for i = 1 to 10 do
    with pairs[i] do
      m = n;
instead of
  for i = 1 to 10
    pairs[i].m = pairs[i].n;
I think the first version is clearer and probably more easily optimizable
than the second.
As far as I understand, in C++ I can achieve roughly the same goals for
static class members by including the 'using namespace tpair;' directive,
while for non-statics it is not possible (there is no way to indicate the
object which should be used).

         Best regards                      Genie

--
--------------------------------------------------------------------
Eugene V. Radchenko           Graduate Student in Computer Chemistry
E-mail: eugene@qsar.chem.msu.su                Fax: +7-(095)939-0290 
Ordinary mail:  Chair of Organic Chemistry, Department of Chemistry,
                      Moscow State University, 119899 Moscow, Russia
*****************  Disappearances are deceptive  *******************


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MATT.95Sep14102849@physics10.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: "Eugene Radchenko" <eugene@qsar.chem.msu.su>
Newsgroups: comp.std.c++
Subject: Pascal-like 'with' statement feasible in C++?
Date: 14 Sep 1995 17:28:49 GMT
Organization: Lab. of Org.Synth., MSU
Approved: matt@physics10.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Sep14102849@physics10.Berkeley.EDU>
NNTP-Posting-Host: physics10.berkeley.edu