|
There must be a good reason why
operator const E*() const;<code><br />
isn't a member of basic_string. Has there been any discussions regarding this on this message board? I really can't come up with a good example where this might be harmful. Maybe just avoiding implicit type conversion is the stand alone reason? Could anyone give an example why this operator is omitted? I'm sure there is a good reason, just can't figure out why. :confused:
|
|
|
|
|
...or maybe I'm just plain stupid. I can't even get the simple HTML tags right
|
|
|
|
|
The main reason why operator const E*() const was banned out of the standard is simply that too many people were againt them. There's a general suspicion about implicit conversions as the can make call to overload functions ambiguous and make the code less clear (allegedly). But the subject is somewhat controversial, and not everybody agrees with the resolution taken by the standard commitee. The example against operator const E*() const that I find most convincing is this: suppose the conversion operator actually exists, then the following piece of code works just fine:
void f(const char *)
{
...
}
...
string s1="Code";
string s2="Project";
f(s1+s2); But the following snippet will fail, although it seems an innocent version of the former:
string s1="Code";
string s2="Project";
const char *p=s1+s2;
f(p); The reason why this fails is that p is no longer valid because the temporary (s1+s2) according to the standard rules might have been deleted when the call to f comes. Introducing c_str does not prevent this problem, but at least make you think twice about it ((s1+s2).c_str() is an eye-catching sentence, isn't it.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
The main reason why operator const E*() const was banned out of the standard is simply that too many people were againt them
Totally agree with them, but in the beginning I was totally against, until I discovered the reasons for this behaviour. Of course as you pinpoint, there are a quite few people that strongly disagree with this, but after all even the standard cannot please all of us.
Although this guys are cleaver , sometimes they just make nonsense decisions like the vector<bool> specialization returning a proxy object , of course this is just plain broken and will be fixed in next one, but this is a sample that this guys sometimes doesn't put the necessary thought on some things.Unfortunately even Stroustroup is against the ideia of incorporating in the C++ core proper multithreading support to do properly multithreading programming(and portable too). They could use policies to provide true thread safe capabilities to stl,not a difficult situation to deal with, and they also could provide true thread safe lazy initializion to c++, for instance in the case of the singleton pattern ..., but no, they don't want that ... lazy guys, and they are suprised that the guys on comp.lang.threads don't like them at all !!!
Joaquín M López Muñoz wrote:
(s1+s2).c_str() is an eye-catching sentence, isn't it
Definitely is ...
Cheers,
Joao Vaz
|
|
|
|
|
(Ok, RAMBLE WARNING!!!)
I hope they never introduce thread safety in the core STL objects such as vector. In my experience, my thread safety requirements extend far beyond just a single instance of a map or vector. Thus, having private locking for these objects does little good.
Then again, my opinion on adding every little thing into the standard is well know.
I was thinking about this stuff this morning and realized something.
1. I don't agree with shops that require that you use 100% standard objects. I think that is counter productive. You just can't have one solution that solves all problems. IMHO, as we get more and more specialized with elements we are adding to the standard, this will become more and more evident.
2. I don't agree with the idea that standard equates to portable. I have had enough years implementing standards to know that there is a huge gap between the ideal standard and that implemented standard.
People might not agree with me, but that isn't the point. If you assume these two points to be true, I think is would be easier to understand why I don't want a lot of junk added to the standard. If feel that people can still get the portability they need from well supported and designed initiatives like BOOST. I really don't see what there is to gain by adding it into the standard. If condition variables get added to the standard, MS isn't going to suddenly decide to add a CV primitive to the XP, W2K, NT4, ME, and 9x. They will just use one of the composite implementations. So what do we really gain? A red rubber stamp that says "this is now standard". Beyond that, what are the real tangible benefits?
If a solution is already portable, why does it suddenly become even more portable when it has the stamp of the standard?
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
WARNING: LONG RANT HERE TOO
Tim Smith wrote:
I hope they never introduce thread safety in the core STL objects such as vector. In my experience, my thread safety requirements extend far beyond just a single instance of a map or vector. Thus, having private locking for these objects does little good.
Hum, you perhaps misinterpreted what I said, I will try to better explain this:
If you readed Modern C++ Design , the 1st chapter deals with the concept of policy classes, this concept is seemed with the strategy pattern, for instance
the policy class :
template<class ThreadModel = ThreadSafeRead>
class CThreadingModel
{
lock();
...
}
The vector instead of :
template <class Type,class Allocator = allocator<Type>> class Vector;
would be:
template <
class Type,
class Allocator = allocator<Type>
class ThreadModelSafety=CThreadingModel
>
Transparent, by default the normal STL behaviour, explicity full MT semantics or other hybrid thread model
Of course this lead to problems mixing classes with different thread models, but hey this is just a thought , besides it's a normal problem when mixing classes with different strategies ...
Tim Smith wrote:
I don't agree with the idea that standard equates to portable. I have had enough years implementing standards to know that there is a huge gap between the ideal standard and that implemented standard.
Of course is a very difficult task, not impossible ... but even so I liked the threading option to be added to the c++ core, not only the stl .
Tim Smith wrote:
If feel that people can still get the portability they need from well supported and designed initiatives like BOOST
A very nice initiative indeed
Tim Smith wrote:
. If condition variables get added to the standard, MS isn't going to suddenly decide to add a CV primitive to the XP, W2K, NT4, ME, and 9x.
Hey Tim, I'm not talking about CVS here , I known that you're still shaken by the not in the very past long arguments held here at CP
But I'll warning you after I'm finally conclude my ICMP protocol article with c# , I'll write a article with a portable thread pool implementation, and suprise, it will have CVs, so I'm expect to be badly beaten by you respecting this and the possible quirks that it may have
Tim Smith wrote:
If a solution is already portable, why does it suddenly become even more portable when it has the stamp of the standard?
Not more portable, only more standard
Cheers,
Joao Vaz
|
|
|
|
|
I strongly disagree with this approach for STL thread safety. It is consistent and would work, but IMHO almost never will suit any programmer's need. Consider for example a for_each operation performed on a std::vector : as for_each only sees the vector thru iterators, this implies that the operation locks and unlocks the vector every time it accesses it. In many occasions one will need that the entire for_each operation is done within a single lock section. Defining appropriate interfaces to achieve this in a generic manner is probably impossible. In more contrived examples, one seeks atomicity for several such operations executed in sequence, and now things become much more complicated than the simpler approach of doing the locking separately. In a nutshell: "atomicity" is too program-specific a concept to be reduced to access-level locking.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Consider for example a for_each operation performed on a std::vector: as for_each only sees the vector thru iterators, this implies that the operation locks and unlocks the vector every time it accesses it. In many occasions one will need that the entire for_each operation is done within a single lock section
Of course with full mt semantics this will lock every operation, but imagine two threads writing to the same vector, and the vector doesn't care about the order in wich threads write, this will improve concurrency , than serializing all the insertions ...
If you want the transversal of vector to be more quickly, you would define the normal thread safe model that most STL implementations use, so using for_each will increase the speed of the loop.
So when you define your vector you must think carefully if this vector will be used much more times in a read scenario than a write scenario or vice-versa.
You could use also template operator= to convert on the fly the vector with threadmodel MT to be used with the normal Thread Read Safe model(possibly very costly or not advisable at all), or you could use the Adaptor Pattern to adapt the class to a different thread model ...
Cheers,
Joao Vaz
|
|
|
|
|
I see what you are getting at, but for an experiensed programmer, both versions (p=s1+s2 and p=(s1+s2).c_str()) should be eye-catching. Most programmers I know uses prefixed variable names to avoid these kind of pit falls. While for an unexperiensed programmer, probably neither is. So I really don't see who the standard commitee is targeting when omitting the operator.
|
|
|
|
|
I'm looking for a tabctrl in which I can add views.
Can somebody help me.
thanx in advance.
CYCOSI
|
|
|
|
|
Maybe it helps.:
http://www.codeproject.com/tabctrl
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
How do you mean ? What's wrong with the one in MFC ? What do you want it to do ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I have created 6 ListViews.
They are working good.
I now want to put them into a tabctrl.
Is it possible with the one in mfc.
If yes, how to do that.
Thanx
|
|
|
|
|
Easy - create six tabs, then create the six tab views as children of the tab control. Then you need to call ShowWindow(SW_SHOW) and ShowWindow(SW_HIDE) on them as the tab selection changes.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Check KB article Q161886.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I use CFileFind and GetLenght() to get size of file.It returns it in BYTE.Now I want to use FILE structure to write or read file,I have to give lenght to this structure and I want to give it in "char".How can I do it?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
CFile::GetLength returns an ULONGLONG , not a BYTE . What do you exactly mean?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
CFile::GetLength returns an ULONGLONG, not a BYTE. What do you exactly mean?
Oh,yes.As I said I have FILE structure and I wanna read all its data charachter by character.I want to give the length of the character I want to read from file to the FILE structure.(which I get it with GetLength() ) Now it gives me ULONGLONG,and I have to give it to FILE in number of charachter.Is it clear or I explain it again?
Thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Is it clear or I explain it again?
Excuse my poor understanding, but I still don't get it. What does "give it to FILE" mean? FILE is an opaque structure you're not supposed to manipulate directly.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
What does "give it to FILE" mean?
The number of charachters I want to read/write from/to FILE.
size_t fread( void *buffer, size_t size, size_t count, FILE *stream );
My problem is how to said to count I want to read/write all the length of file.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Ok, now I got it. Well, stdio.h IO is basically limited to 32-bit sizes (see for instance fseek ), so files greater than 4GB might be a little hard to deal with. You have the following options:- Ignore files greater than 4GB (they're truly exceptional, after all) and just truncate the
ULONGLONG values to fit into a size_t .
- Read the file in moderately sized chunks. I'd do it this way unless you absolutely need to have all the file contents in one big buffer.
- Try dividing the total amount of bytes between parameters
size and count . For instance,
fread(pb,0xFFFFFFFF,0xFFFFFFFF,fp) should read (232-1)(232-1)~264 bytes. I'm not sure this will work though. Also, please note you're gonna have trouble allocating such a monster buffer.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thaank you Joaquin,like always
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
If you have no trouble allocating the buffer, you should be able to just type cast the ULONGLONG to a size_t for your count parameter.
Just keep in mind that files can be a lot larger than your address space allows for, in which case you might want to look into memory mapped files.
|
|
|
|
|
hmmmm,thank you
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
A char is one BYTE , so when GetLength() returns the file size, it is giving you the number of BYTE s, thus the number of char s
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|