edA-qa | 30 Sep 19:43

const references and synonyms

This is a recall of a previous constant discussion.  I would like to 
differentiate between const instances and const references.

//the following is a shared reference to a const heap instance
T const ^ ref;	

//the following is a const shared reference to a heap instance
T ^ const ref;

//const references disallow rebinding, ro conversion to non-const
//references
ref @= otherRef;	//error, cannot rebind

void func( T^ param );
func( ref );	//error, cannot conver to non-const reference

This then needs to be extended to synonyms in the function call syntax. 
  To show why, here is an example of what bad happens without:

template<typename T>
void beNice( T& ref ) {
	ref @= somethingElse;
}

The callers of this function have no guarantee that their shared 
references aren't being rebound -- while sometimes they may want this, 
other times clearly not.  So:

template<typename T>
void beNice( T const& ) {
	ref @= somethingElse;	//fails, cannot rebind const reference
}

This of course requires a "^ const" to have meaning, which I've define 
above.

--

-- 
edA-qa mort-ora-y
Idea Architect
http://disemia.com/

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl

Gmane