Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » _pick understanding
_pick understanding [message #26369] Tue, 27 April 2010 21:08 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi there,

in
http://www.ultimatepp.org/srcdoc$Core$pick_$en-us.html

there is _pick explained as
#define _pick const


but when i look in code the _pick definition in MSC environment is empty.. why? setting it to const there as well compiles well..
is there any thing special to MSC to consider? just out of curiosity..

Defs.h:277
#ifdef COMPILER_MSC
#define pick_
#else
#define pick_ const
#endif


another question:

Topt.h:252
template <class T, class B = EmptyClass>
class DeepCopyOption : public B {
public:
	friend T& operator<<=(T& dest, const T& src)
	{ if(&dest != &src) { (&dest)->T::~T(); ::new(&dest) T(src, 1); } return dest; }
	friend void DeepCopyConstruct(void *dest, const T& src)
	{ ::new (dest) T(src, 0); }
	friend T *DeepCopyNew(const T& src)
	{ return ::new T(src, 0); }
};


uses 1 for param in <<= operator while link above also states that the second int parameter is just for distinciton and ignored. is it evaluated anywhere? maybe to indicate a reuse??

IMHO _pick should be explained a bit better, i understand the problem leading to _pick solution, but especially the explanation
Quote:


C++ disallows binding temporaries to non-const references - and that is unfortunately just the thing we need to do here, as we need to change the source temporary returned from a function.


should be visualised by a (not permitted) code snippet as well.
Re: _pick understanding [message #26372 is a reply to message #26369] Wed, 28 April 2010 11:27 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
I believe that the different defines are because in default mode, MSC is not 100% compliant with C++ standard and is a little more allowing than it should be. Basically, it allows you to not use const in some cases where const should be used. This dates back from the golden era of MFC AFAIK.

Please correct me if I'm wrong.

I would like to see const added to pick for MSC too on a pure ideological level, but I have no practical consideration that would make me change that.
Re: _pick understanding [message #26381 is a reply to message #26372] Wed, 28 April 2010 20:38 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
as far as trying, it works Smile so far...

any ideas on the int value in special copy constructor, why sometimes 0 sometimes 1..?
Re: _pick understanding [message #26396 is a reply to message #26372] Thu, 29 April 2010 23:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cbpporter wrote on Wed, 28 April 2010 05:27

I believe that the different defines are because in default mode, MSC is not 100% compliant with C++ standard and is a little more allowing than it should be. Basically, it allows you to not use const in some cases where const should be used. This dates back from the golden era of MFC AFAIK.

Please correct me if I'm wrong.



You are right.

Quote:


I would like to see const added to pick for MSC too on a pure ideological level, but I have no practical consideration that would make me change that.


There is a practical reason why we "exploit" this MSC bug:

Doing so, we are able to catch some pick semantics bugs at compile time. E.g.

void Foo(const Vector<int>& b) {
   Vector<int> a;
   a = b;
}


does not compile with MSC (which is correct).

(Frankly, I believe that M$ got it right here and standard has it wrong Smile

Note: Thankfully M$ seems to use its own semantics in MFC in some places, therefore they perhaps have to keep this non-compliance to standard.

Mirek
Re: _pick understanding [message #26397 is a reply to message #26381] Thu, 29 April 2010 23:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 28 April 2010 14:38

as far as trying, it works Smile so far...

any ideas on the int value in special copy constructor, why sometimes 0 sometimes 1..?


The parameter is there only to distinguish the copy constructor. The value is ignored.

(Frankly, if I would do this again, I would probably used some sort of enum or other special type. But that would be only a minor difference).

Mirek
Re: _pick understanding [message #26405 is a reply to message #26397] Fri, 30 April 2010 09:17 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thanks all, that claerified it a bit
Previous Topic: FEATURE: T* ArrayIndex::Detach(int i) AND mini fix
Next Topic: what about VectorBiMap / ArrayBiMap ?
Goto Forum:
  


Current Time: Mon Apr 29 00:45:01 CEST 2024

Total time taken to generate the page: 0.91674 seconds