🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Proposal for a new access specifier

#2212
From: Eric Biederman
Date: Mon, 16 Oct 1995 08:43
82 lines
2991 bytes
In article <DGEovz.DKv@mv.mv.com> ENGR@GSSI.MV.COM (Michael Furman) writes:

[ snip ]
     I can explain what I would suggest (trying to invent C/C++ compatible 
   syntax on fly). I do not want to change access syntax at all but use 
   additional 
   specifier to variable declaration / definition. It is "access type" that can 
   be:

     1. Memory (default): regular C/C++ variable that will be mapped to some 
   memory.
     2. Emitter: in this case you must specify access function to call when 
   somebody
	will read value of this "variable".
     3. Collector: in this case you must specify access function to call when 
	somebody will write value of this "variable".

   (I am not sure about words emitter and collector. And I am sorry about my 
   English)

   Declaration of some class may look like:

      class X
	{
      private:
	int x_;
      public:
	int emitter x {return x_;}
	collector x(int &arg) {x_ = arg;}
	}

   or, may be:

	class Y
	  {
	public:
	  int emitter x {int t; scanf("%d", &t); return t;}
	  collector x(int &arg) { printf("%d\n", arg); }
	  }

   I think it does not break any existent code (but needs two or even three 
   extra reserved words).

   Any comments?

This capability is already in the language, there are no changes
needed to create it.  There is though the need for a realization that
you need a seperate type for your variable. 

Your example then becomes
	class Y
	  {
	public:
	  operator int () { int t; cin t; return t;}
	  int operator = (int arg) { cout << arg; return arg; }
	  }

So, there isn't a need for a change to allow the capability you want.
On the other hand there might be call for a standard template class
that can implement semantics like read only or write only.

Example:
template <class T>
class write_only {
private:
  T & ob;  // There's no way to read T;
public:
  read_only(T & obj) : ob(obj) {}
  ~read_only() {}
  void operator = (const T & obj) { ob = obj; }
}

Now it would be useful for a write only variable if there were a
syntax for static references that allowed them to be optimized out,
and not need to be initialized in every constructor.


---
[ 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: <EBIEDERM.95Oct16003412@cse.unl.edu>
Path: arc1-ca.pugleaf.net!news.duke.edu!agate!agate!Matt
References: <199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <DG6q6J.EEt@mv.mv.com> <45d5r1$fk4@mujibur.inmind.com> <DGEovz.DKv@mv.mv.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.duke.edu!agate!agate!Matt
From: ebiederm@cse.unl.edu (Eric Biederman)
Newsgroups: comp.std.c++
Subject: Re: Proposal for a new access specifier
Date: 16 Oct 1995 08:43:15 GMT
Organization: University of Nebraska--Lincoln
Approved: Matt@Austern
Message-ID: <EBIEDERM.95Oct16003412@cse.unl.edu>
References: <199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern>
 <44spqj$j37@nn.fast.net> <DG6q6J.EEt@mv.mv.com>
 <45d5r1$fk4@mujibur.inmind.com> <DGEovz.DKv@mv.mv.com>
NNTP-Posting-Host: austern.hip.berkeley.edu