|
Chris Losinger wrote:
80%? i'd say more like 95%.
It's probable that part of the reason so many people don't know this stuff is that their compiler does not support it.
Chris Losinger wrote:
i bet there's not one dev here at where i work that knows what Koenig lookup is
I can pronounce it, but then I'm half German, and I used to watch Space 1999. I've just done a google search though - this could be my one thng to learn for today
Chris Losinger wrote:
"partial specialization", maybe one or two of us know what that is.
*really* ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
yep, it was one of my new bits of knowledge. that and the sad fact that SGI's STL has a class called "rope", but VC's doesn't. rope apparently makes life nicer when dealing with large strings (think XML docs). sigh.
(it's "kur-nig", right?).
*really* ?
yep. as clever as templates are, they don't really get much use here - outside of basic use of MFC and STL collection classes. we rarely write our own template classes, and never need something as esoteric as partial specialization on the things we do write. it's just the nature of the apps we write.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Chris Losinger wrote:
(it's "kur-nig", right?).
Yup.
SGI also has a hash table container I believe, or is that just STL port ? I keep meaning to install STLport, but I never get to it.
Chris Losinger wrote:
yep. as clever as templates are, they don't really get much use here
We don't *use* templates much either, but I try to make a habit of learning as much C++ as I can, I write apps in my own time that exist solely as excuses to use things I want to learn about. It's my opinion that the only way to use more than a subset of the language is to make sure you learn it. I won't use templates ( or anything ) for the sake of using it, but I like to think I have a good idea of the available options when choosing which is the best.
I can't imagine partial specialisation being something too many people would need often. I'd just like the chance to decide for myself if it's useful, instead of M$ deciding for me.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian Graus wrote:
but I try to make a habit of learning as much C++ as I can, I write apps in my own time that exist solely as excuses to use things I want to learn about.
yes, in that case, i'm all for adding new and interesting capabilities.
Christian Graus wrote:
SGI also has a hash table container I believe, or is that just STL port ?
hash_map. i saw a few references to that when i was looking around for the "rope" stuff. i know it's in SGI's, not sure about STLPort. sounds like something that could give MFC's CMap a challenge.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Chris Losinger wrote:
hash_map. i saw a few references to that when i was looking around for the "rope" stuff. i know it's in SGI's, not sure about STLPort. sounds like something that could give MFC's CMap a challenge.
I'm quite happy with map, the binary tree is fast enough for me. Is a hash table faster ? I believe they intend on adding one to the STL as part of the next standard.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Chris Losinger wrote:
yep. as clever as templates are, they don't really get much use here - outside of basic use of MFC and STL collection classes. we rarely write our own template classes, and never need something as esoteric as partial specialization on the things we do write. it's just the nature of the apps we write.
I couldn't agree more. Out of a team of 8 developers only two of us here have written any template classes for the project, although I think they'll become more widespread as we include more COM/ATL code in the product.
Andy Metcalfe - Sonardyne International Ltd
Trouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++ 5.0/6.0
"I'm just another 'S' bend in the internet. A ton of stuff goes through my system, and some of the hairer, stickier and lumpier stuff sticks."
- Chris Maunder (I just couldn't let that one past )
|
|
|
|
|
...and you're probably right, if "using" means "using directly". The point is that these features are primarily of use to library implementers - for making life easier for developers and for making more robust and more efficient programs.
The fact that Microsoft have chosen to not update its C++ compiler in any significant way makes it clear to me that they're not interested in supporting C++ development under Windows (perhaps because the language is not under their control?). Implementing these compiler features are difficult, but it's not THAT difficult. They've had plenty of time (several years) and they have vast resources at their disposal.
Sorry for posting anonymously, but this isn't my regular crowd and I'll leave now. I hope I haven't offended anyone.
|
|
|
|
|
I know now. Found some examples on good old google.
Giles
|
|
|
|
|
What many people don't appreciate is that you don't have to know about partial template specialization or Koenig lookup to be able to use a library that uses these features.
Most developers will not write PTS code, but many may start to use libraries such as Blitz++ that make extensive use of PTS.
Here's an example. Suppose I want to use the STL library's std::list.sort() member function. In true STL I can choose to sort the list on any predicate I choose, but in Microsoft STL (from VC++ 6.0, all service packs) I can only sort using the predicate greater(). I don't have to care why Microsoft STL doesn't work (at the time, it was another obscure C++ template compliance problem that 99% of developers didn't understand or care about) to be annoyed that I can't use std::list to sort a list by arbitrary predicates (imagine a list of objects with attributes FirstName and SocSecNum and that I want to be able to sort by predicates by_name() and by_ssn()).
Similarly, there are many libraries out there that will continue not to be usable by VC++ until it supports PTS and other standards items. We don't have to understand all the internals of a library to use it, but the compiler must be compliant to work with it.
|
|
|
|
|
I can't use std::list to sort a list by arbitrary predicates
???
of course you can.
list::sort
void sort();
template<class Pred>
void sort(greater<T> pr);
just because the parameter is called "greater" on the function prototype doesn't mean it can't be comparing in whatever direction you want. if fact, the sample for list::sort shows how to sort with a custom predicate.
that said, you do have a good point about cross platform/compiler libraries. even so, every cross platform library i've ever seen is chock-full of #ifdefs and compiler specific-header files that you need to swap out when you install the lib.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Chris Losinger wrote:
I can't use std::list to sort a list by arbitrary predicates
???
of course you can.
list::sortvoid sort();template void sort(greater pr);
just because the parameter is called "greater" on the function prototype doesn't mean it can't be comparing in whatever direction you want. if fact, the sample for list::sort shows how to sort with a custom predicate.
There is a bug in the STL as delivered by Microsoft. The STL example you cite does not run as it is supposed to. The basic problem is that while you can subclass struct greater<t>, when you run list<t>::sort(specialized_greater_class<t>), it will call greater<t>::operator(), not specialized_greater_class<t>::operator(), so you can't sort on multiple predicates after all. P.J. Plauger confirmed this as a bug in 1999 and offered a solution (see http://groups.google.com/groups?hl=en&selm=7t385o%24t6d%241%40news.ime.net), but Microsoft, despite having released a couple of service packs since then, has not patched this STL bug.
Consider the following code:
#include <iostream>
#include <list>
using namespace std;
struct Foo
{
int m_nValue;
Foo(int val = 0) : m_nValue(val) {}
bool operator >(const Foo& rhs_) const;
bool operator <(const Foo& rht_) const;
bool greater_mag(const Foo& rht_) const;
};
bool Foo::operator <(const Foo& rhs_) const
{
return m_nValue < rhs_.m_nValue;
}
bool Foo::operator >(const Foo& rhs_) const
{
cerr << "Called >" << endl;
return (m_nValue > rhs_.m_nValue);
}
bool Foo::greater_mag(const Foo& rhs_) const
{
cerr << "Called greater_mag" << endl;
return abs(m_nValue) > abs(rhs_.m_nValue);
}
template <class T_> struct greater_magnitude : public greater<T_>
{
bool operator()(const T_& x, const T_& y) const {
return (x.greater_mag(y));
}
};
int main(int argc, char* argv[])
{
list<Foo> flist;
flist.push_back(Foo(1));
flist.push_back(Foo(-2));
flist.push_back(Foo(3));
flist.sort(greater_magnitude<Foo>());
list<Foo>::const_iterator it = flist.begin();
while (it != flist.end())
cout << it++ ->m_nValue << " ";
cout << endl;
return 0;
}
Compile it with the STL that ships with MSVC (patched to SP5). When you run the program it outputs
Called >
Called >
3 1 -2
Note that the function is not calling the subclass's greater_magnitude::operator(), but the parent class's greater::operator().
Now patch the STL list header, as P.J. Plauger recommends (http://groups.google.com/groups?hl=en&selm=7t385o%24t6d%241%40news.ime.net) and the program runs properly.
Called greater_mag
Called greater_mag
3 -2 1
|
|
|
|
|
Chris Losinger wrote:
i'd bitch a blue streak
I'm still trying to work out what this colourful phrase means (though I get the gist )
cheers,
Chris Maunder
|
|
|
|
|
according to the always helpful merriamwebster.com, a blue streak is
Main Entry: blue streak
Function: noun
Date: 1830
1 : something that moves very fast
2 : a constant stream of words (talked a blue streak)
in this definition, they neglect to mention the connotations of "blue". but, i'll share them, here (emphasis mine):
Main Entry: blue
Pronunciation: 'blü
Function: adjective
Inflected Form(s): blu·er; blu·est
Etymology: Middle English, from Old French blou, of Germanic origin; akin to Old High German blAo blue; akin to Latin flavus yellow
Date: 13th century
1 : of the color blue
2 a : BLUISH b : discolored by or as if by bruising (blue with cold) c : bluish gray (blue cat)
3 a : low in spirits : MELANCHOLY b : marked by low spirits : DEPRESSING (blue funk) (things looked blue)
4 : wearing blue
5 of a woman : LEARNED, INTELLECTUAL
6 : PURITANICAL
7 a : PROFANE, INDECENT (blue movie) b : OFF-COLOR, RISQUé (blue jokes)
8 : of, relating to, or used in blues (blue song)
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Please somebody correct me if I am wrong, but I believe another area where VC++ is not compliant is for loops. "Standard" code would look like this:
for(int i = 0; i < 5; i++)
{
// i is in scope
}
// i is not in scope here!
for(int i = 0; i < 10; i++)
{
// okay, i is in scope again
}
That is, a variable declared in a for loop is local only to that loop. But in VC++, the above code won't compile, becuase variables defined in a for loop are in scope even after the foor loop.
I personally think the standard makes more sense than what VC++ does, but that's just me. And you can get around this by declaring variables before the for loop as well.
Now, why Microsoft will keep anachronisms like this in VC++ so that older code can still compile, yet totally overhaul Visual Basic so that very little old code will compile is anyone's gues...
(Glad my team at work no longer has to maintain any VB code..)
The early bird may get the worm, but the second mouse gets the cheese.
|
|
|
|
|
Actually, this is one of the (too few) things that are fixed in VC++ 7. Well, kind of. You can enable the standard-compliant behaviour through an option - the default is the old, non-standard scoping...
|
|
|
|
|
That has been the case for a long time. If you disable MS extensions, that shouldn't happen anymore.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Templates are the first thing that comes to mind, partial template specialisation for one. There is a VERY cool book called Modern C++ Design that I am salivating over getting, but there is no point - the examples do not compile under VC++.
As for a list, try reading WDJ, they have a new bug or two every month that they bring to M$ attention. Usually it's not documented by them, and usually they say 'we knew about this, it will be fixed in a later release'.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
It's not the existing code, but the future code base, that really concerns me most. With the heavy weight on .NET development from MS, we'll start to see more and more code using non-Standard C++ keywords (such as __gc, __sealed, __property, __event etc.) in our future VC++ projects. Picture your code base in about 5 years from now, filled with all these keywords and suddenly your boss asks you to port it to another platform. I wish you a very good luck.
So it's nice to see Microsoft's attempt to make native C++ compiler more Standard compliant, but I'm afraid, the .NET and hence managed C++ initiative will work against the progress made in the former case.
Oh yes, as some .NET zealot may put it, it's a natural and modern evolution of C++ language. Don't you think so?
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
I am not arguing that the compiler shouldn't be compliant. But I have to wonder what people expect that compliance is going to buy them.
Sure, the new language features would be nice. But hell, I like a lot of the MS extensions. And a few cases when MS didn't go with the standard such as variable scope in for loops.
It won't produce a common set of sources for things like STL. There will still be tons of #ifdefs to overcome differences in compilers. For every standard statement, there are 5 things a compiler can do that is either undefined, unspecified, or unpredictable.
a [i] = i++;
(If I am remembering the example right) Depending on your compiler, that will execute differently. The standard doesn't specify when the actual post increment has to happen as long as it happens prior to the next statement.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I believe you mean a[i++] = i, because the standard only says the variable is incremented after the value is used, not if it's after the line has been executed.
But this is a good example of code that people should not be writing, for exactly that reason - it's behaviour is undefined and therefore even your current compiler would be within it's rights to change that behaviour between releases.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
That it's. When you install MSVC its default setting for warning level is 3 and all extentions is turned on. I have impression that majority of programmers just use these settings without worrying about compliance. "Why to bother? We'll stick with MS until end of times..". I saw a lot of code that simple switch from warning level 3 to 4 was exposing many bugs thanks to "innocent" warnings about varaibles used without initialization, unreferenced parameters etc..
Even with current compiler's compliance big amount of code could be significally improved.
Unfortunately, many CRT/STL/SDK headers produce level 4 warning while being compiled. Among them are "nonstandard extension used" warnings, too. So, I guess, coders are always stand against temptation to ignore many warnings and incompliances in order to get "clean" Output window in MSVC.
|
|
|
|
|
One has to wonder how many lines of VB people will be changing to compile under VB.Net. In the case of C++ there is a publically available standard and I think anyone who deviates enough from that for compilation on a standards compliant compiler to not work is being hoist by their own petard. This is *not* a good reason for compiler manufacturers to skimp on the sort of sexy features of the language that VC currently lacks.
Anyone who says they are unwilling to change their code to compile under a standards compliant compiler is scared of their own mistakes and should go use VB instead. If EVERY change I had to make was a result of my writing incorrect C++ code, then I would accept it as a learning experience. I have in the past found that I've done things in a less than optimal way at work, and I've gone through my code in my own time to change it to something better/safer/more correct. Surely we all feel the same way ? The idea is to keep learning and improving ourselves, not sitting on our thumbs and thinking we know it all. I sure as hell don't.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Well said. Until C++ standard compliant, the C# standardization politics is laughable
There is no excuse for non-stardard C++ compiler, especially when extensions are being added without notice!
The main problem with standard compliant compiler is MS own source codes, not ours and there is no reason to let it look like we will have problems.
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for programming contract anywhere!
|
|
|
|
|
Christian Graus wrote:
If EVERY change I had to make was a result of my writing incorrect C++ code, then I would accept it as a learning experience. I have in the past found that I've done things in a less than optimal way at work, and I've gone through my code in my own time to change it to something better/safer/more correct. Surely we all feel the same way ? The idea is to keep learning and improving ourselves, not sitting on our thumbs and thinking we know it all. I sure as hell don't.
Well said, Christian.
CodeGuy
The WTL newsgroup: now 1060 members! Be a part of it. http://groups.yahoo.com/group/wtl
|
|
|
|
|