Thursday, April 30, 2015

Digest for comp.lang.c++@googlegroups.com - 25 updates in 6 topics

Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 01:32PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
 
> Human someHoman;
 
> NOT
> Human someHuman();
 
Because for the compiler this would look like a function declaration. Yes,
it's not fully consistent, that's one of the reasons the new brace
initialization syntax was introduced in C++11 so now you can write:
 
Human someHuman{};
 
for defining a variable.
legalize+jeeves@mail.xmission.com (Richard): Apr 30 07:03PM

[Please do not mail me a copy of your followup]
 
Doug Mika <dougmmika@gmail.com> spake the secret code
>object using:
>DisplayElement<int>()
 
>am I declaring it on the stack or the heap? And when and by whom is it deleted?
 
It's on the stack and its lifetime is that of the enclosing
expression, namely the function call where this anonymous instance is
supplied as an actual argument.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Öö Tiib" <ootiib@hot.ee>: Apr 30 04:02PM -0700

On Friday, 1 May 2015 01:10:05 UTC+3, Stefan Ram wrote:
> >scope.
 
> IIRC, this is valid for /const/ lvalue references and for
> rvalue references, but not for /non-const/ lvalue references.
 
Are these really called "lvalue references" now?
It is impossible to initialize such a reference to non-const with
temporary unless you use Microsoft Visual C or other non-standard
and it seems that at least in visual c it also affects life-time
of temporary.
Doug Mika <dougmmika@gmail.com>: Apr 30 02:15PM -0700

Hi to all
 
I have read much about passing parameters and objects by value and reference, and I think I understand all these concepts. The thing that is providing me with confusion is passing "functions" as parameters, be it by reference or by value. My books don't cover this and I don't quite know what phrase to search to find info on this. Does anyone know of any sites on the net that cover how functions are passed as parameters? After all they don't exist the same way in memory, or do they? Do we have such a thing as instances of functions?
 
Thanks
Doug
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 30 05:29PM -0400

On 4/30/2015 5:15 PM, Doug Mika wrote:
> I have read much about passing parameters and objects by value and
reference, and I think I understand all these concepts. The thing that
is providing me with confusion is passing "functions" as parameters, be
it by reference or by value. My books don't cover this and I don't quite
know what phrase to search to find info on this. Does anyone know of any
sites on the net that cover how functions are passed as parameters?
 
I don't, sorry.
 
After all they don't exist the same way in memory, or do they? Do we
have such a thing as instances of functions?
 
You can think that functions are passed around as pointers, and functors
(objects of classes that define their own op() member function) are
passed around like all other objects. Look at a pointer to the function
as the address in the computer memory of the first machine instruction
into which that function code is translated. In C++ functions (pointers
to them) also have types, so you can't pass a function with one set of
argument types where a function with a different set is expected, but
there are sometimes conversions.
 
Perhaps "Inside the C++ Object Model" by Lippman contains more on that
and other topics. Check it out.
 
V
--
I do not respond to top-posted replies, please don't ask
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 05:13PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
> and I don't quite know what phrase to search to find info on this.
> Does anyone know of any sites on the net that cover how functions are
> passed as parameters?
 
Not really. The syntactis rules are quite confusing and any tutorial
attempting to cover them would be confusing as well. The good thing is
that you rarely need passing functions in C++ (virtual functions and
functors are better for many usage cases) and when you need them you can
use only a relatively small clear subset of the syntax - function
pointers.
 
See, in any case what is actually passed around is a pointer to the
function, not the function itself, whatever that would mean. Effectively,
functions are never passed "by value". C++ is not LISP. So one needs to
deal just with function pointers, and these are small simple objects
similar to data pointers. Pointers are naturally passed by value, and the
pointed functions themselves stay whereever they are.
 
> After all they don't exist the same way in
> memory, or do they? Do we have such a thing as instances of
> functions?
 
No. There is something similar - instantiation of templates, which can
produce multiple functions, but this happens at compile time and at
runtime these would be all different unique nonchanging and non-moving
functions (*).
 
(*) In an ideal world. In practice I have had a bug where a static
library was linked into different dynamic libraries so there were
multiple instances of the same functions present in the process. This was
all fine until a memory corruption bug ruined one of those copies. The
result was that when a certain function was called via one dll everything
worked fine, but if the same function with the same arguments was called
through another dll all hell broke loose. So yes, in practice one can
have multiple different "instances" of a function. But this would be a
bug, not a feature.
 
Cheers
Paavo
legalize+jeeves@mail.xmission.com (Richard): Apr 30 10:47PM

[Please do not mail me a copy of your followup]
 
Doug Mika <dougmmika@gmail.com> spake the secret code
>reference, and I think I understand all these concepts. The thing that
>is providing me with confusion is passing "functions" as parameters, be
>it by reference or by value.
 
When you pass the name of a function as a parameter, it is always an
implicit pointer to the function and takes the same amount of space on
the argument stack as any other pointer.
 
#include <iostream>
 
void f()
{
std::cout << "Hi!\n";
}
 
void g(void fn())
{
fn();
}
 
int main()
{
g(f);
}
 
prints "Hi!\n" when you run it.
 
The names of functions always implicitly decay to a pointer to the
function. There isn't anything other you can do with the name of a
function as a value other than take its address, either implicitly or
explicitly.
 
The syntax gets a little uglier for pointers to member functions, but
the idea is the same -- you can only take the address of a member
function and pass it as a pointer or a reference. A reference in C++
is mechanically equivalent to a pointer but has one important semantic
difference -- a reference can never be NULL, so you can use references
without checking whether or not they refer to something (unlike a
pointer).
 
If you're talking about "function objects" such as the things passed
to the C++ standard library algorithms like "for_each", those are
either plain old function pointers as discussed above, or they are
instances of classes that implement operator().
 
In the case of passing function objects (also called functors), they
are passed just like any other object.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
ram@zedat.fu-berlin.de (Stefan Ram): Apr 30 09:52PM

>Unfortunately to you C++ language has already given a meaning
>to 1. It is integer constant
^
an
 
It's called »integer constant« in C (»6.4.4.1 Integer constants«),
but »integer literal« in C++ (2.13.2 Integer literals).
 
The expression »unfortunately for you« is much more common than
»unfortunately to you«.
 
»C++ language« without »the« sounds odd. Just look at the famous
book by Bjarne Stroustrup. It's not called »C++ language«, it's
called »The C++ programming language«. So I'd write this as
(also notice the comma)
 
»Unfortunately for you, the C++ language has already given a meaning
to 1. It is an integer constant«
 
or, with slightly more emphasis on »already«:
 
»Unfortunately for you, the C++ language already has given a meaning
to 1. It's an integer constant«
 
However, being an integer literal is /not/ the meaning of the
integer literal 1. It is only /a part/ of its meaning, it is one of
its (lexical) categories (one of its non-terminal symbols). However,
its meaning comprises more parts: it has the type »int«, the value
»one«, and so one.
 
(However, this would still not be quite correct, when one is
looking at the »1« in isolation! Because in this case, it also
might appear in a C program as part of
 
identifier123
"string123"
123
/*comment123*/
...
 
, but this was not the way it was used in the OP.)
ram@zedat.fu-berlin.de (Stefan Ram): Apr 30 10:09PM

>C++ standard does say "automatic storage" (that is usually stack) and
>"dynamic storage" (that is usually heap).
 
It always says »automatic storage duration« and »dynamic
storage duration«.
 
The difference between »automatic storage« and »automatic
storage duration« is just like the difference between a »new
bus« and a »new bus driver« (or a lightning and a lightning bug).
 
>initialize reference variable with it. If you initialize reference
>variable with it then it will be destroyed when that variable leaves
>scope.
 
IIRC, this is valid for /const/ lvalue references and for
rvalue references, but not for /non-const/ lvalue references.
ram@zedat.fu-berlin.de (Stefan Ram): Apr 30 10:23PM

>use only a relatively small clear subset of the syntax - function
>pointers.
 
»Function pointers« belong to the runtime model. They are values
(or objects).
 
The syntax describes C++ programs as source text, it's part of the
source code model.
 
Therefore, values and objects cannot be a »subset« of the syntax.
 
You might actually think of »function pointer expressions«. But these
also are not a /subset/ of the syntax, but rather a /part of a source
code/ (which in turn is being described by the syntax).
 
The syntax, to me (and some others), is the set of all terminal
representations of the start symbol of the C++ grammar, that is,
the set of all valid programs. Were function pointers a subset
of the syntax, they would be a set of programs.
legalize+jeeves@mail.xmission.com (Richard): Apr 30 06:59PM

[Please do not mail me a copy of your followup]
 
Paavo Helde <myfirstname@osa.pri.ee> spake the secret code
>> haven't yet.
 
>IMO you have not lost anything. My list of complaints about C::B is so long
>I cannot even start.
 
I heard it had some refactoring support, so I was going to run my
refactoring test suite against it:
<https://github.com/LegalizeAdulthood/refactor-test-suite>
 
So far, CLion has been the best performer against this test suite.
(Which reminds me, I need to rerun the suite against the CLion 1.0
release build.)
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Ian Collins <ian-news@hotmail.com>: May 01 07:22AM +1200

嘱 Tiib wrote:
>> haven't yet.
 
> From general purpose IDEs NetBeans understands and highlights C++ lot
> better than Code Blocks and tools seem also easier to integrate to it.
 
NetBeans remote build options and lack of visual clutter are some of the
reasons I prefer it over Eclipse. When developing for multiple
compilers/targets "build all" from the IDE is a blessing!
 
--
Ian Collins
David Brown <david.brown@hesbynett.no>: Apr 30 10:56PM +0200

On 30/04/15 21:22, Ian Collins wrote:
 
> NetBeans remote build options and lack of visual clutter are some of the
> reasons I prefer it over Eclipse. When developing for multiple
> compilers/targets "build all" from the IDE is a blessing!
 
My builds are always done with external Makefiles, rather than the IDE's
- I prefer to keep my source code and build system independent of the
editor in use.
 
Maybe I'll give NetBeans a shot some time - I've only heard good things
about it. But Eclipse is the standard in the embedded world, and almost
all integrated development tools are based on it (except Microchip uses
NetBeans, and Atmel uses MSVC). It's easy enough to use a different
editor, and Makefiles keeps the builds independent of the IDE, but
sometimes low-level debugging can't be done with anything other than the
vendor's tools - and that usually means Eclipse.
 
Eclipse used to be painfully slow, buggy and bloated, but I find it
works well these days.
Daniel <danielaparker@gmail.com>: Apr 30 04:25AM -0700

On Wednesday, April 29, 2015 at 5:12:05 PM UTC-4, Chris Vine wrote:
> > Leigh, please don't swear here.
 
> I wish you could get it into your somewhat curious system of reasoning
> that "fuck" is not swearing.
 
Where I grew up, it was used as punctuation.
 
Daniel
woodbrian77@gmail.com: Apr 30 11:38AM -0700


> http://en.cppreference.com/w/cpp/string/basic_string/basic_string
 
> It seems like that would help avoid some allocations and
> moving of strings.
 
I've done some performance testing now comparing my original ctor:
 
explicit failure (char const* w) : whatStr(w) {}
 
with this one:
 
explicit failure (char const* w, int tot) {
if (tot > 0) whatStr.reserve(tot);
whatStr= w;
}
 
I used a test program like this:
 
#include "ErrorWords.hh"
 
void throws ()
{
throw cmw::failure("In the beginning was the Word.", 41) << 33 << " abcdefg";
}
 
int main ()
{
int p = 0;
for (int i = 0; i < 100000; ++i)
{
try {
throws();
} catch (std::exception const& ex){
++p;
}
}
printf("p is %d\n", p);
return 1;
}
 
--------------------------------------------------
 
The original version was about 20% slower than the newer
version on PC-BSD 10.1 and clang 3.4.1. I believe the new
ctor that I proposed could do a little better than the version
that first reserves and then copy-assigns the string. And it
would be easier to use as you wouldn't have to count/include
the length of the original text that you pass to the ctor.
 
I hope this ctor will be added to C++ 2015.
 
 
Brian
Ebenezer Enterprises - "What do you have that you have not received?"
1st Corinthians 4:7
 
http://webEbenezer.net
woodbrian77@gmail.com: Apr 30 11:41AM -0700

On Thursday, April 30, 2015 at 6:25:44 AM UTC-5, Daniel wrote:
 
> Where I grew up, it was used as punctuation.
 
I'm sorry to hear that.
Dombo <dombo@disposable.invalid>: Apr 30 08:45PM +0200

Op 29-Apr-15 23:11, Chris Vine schreef:
> that "fuck" is not swearing. It is bad language (for some of the more
> fastidious at least, personally I couldn't care a fuck).
 
> Swearing is an offence to your god. Bad language is an offence to man.
 
Fuck god then.
Ian Collins <ian-news@hotmail.com>: May 01 07:15AM +1200

> that first reserves and then copy-assigns the string. And it
> would be easier to use as you wouldn't have to count/include
> the length of the original text that you pass to the ctor.
 
I think you are missing the point - throwing an exception is an
exceptional event and the cost of constructing an exception object is
seldom a concern given all of the other overheads involved.
 
--
Ian Collins
Christian Gollwitzer <auriocus@gmx.de>: Apr 30 08:28PM +0200

Am 30.04.15 um 19:49 schrieb Richard:
> the signature of for_each which takes the functor by value. To get
> what you want, you have to use a referring wrapper like boost::ref, or
> have your functor reference the count held elsewhere:
 
...or better yet, forget about for_each - this was just an auxiliary
construct in C++ before 11, to avoid ugly for loops. Nowadays we have
 
for (auto i: vecIntegers) {
Result(i)
}
 
which does what you want, is more readable in my opinion and can also be
done without a functor, if the only reason for the functor was for_each
in the end.
 
Christian
Doug Mika <dougmmika@gmail.com>: Apr 30 11:29AM -0700

I guess one more newbie question:
 
When this functor is passed by value, I assume it's the entire object (along with implementation of operator()) that is passed by value, and that if I have a copy constructor implemented, it will be used to pass that entire functor by value, correct?
 
Thanks
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 01:36PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
> for_each(vecIntegers.begin(),vecIntegers.end(),Result);
 
> the result of Result.Count is 0!!!, WHY isn't it 10????? Afterall, I
> call the oprator() 10 times!
 
Change this line to:
 
Result = for_each(vecIntegers.begin(),vecIntegers.end(),Result);
 
Victor already explained why your version did not work.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 01:51PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
 
> I guess one more newbie question:
 
> When this functor is passed by value, I assume it's the entire object
> (along with implementation of operator())
 
An object does not contain any compiled machine code, so implementations of
any functions or operators are not copied. Also, as the compiled code does
not change during the run, it would be the most silly thing to copy it
around in zillions of exemplars.
 
> that is passed by value, and
> that if I have a copy constructor implemented, it will be used to pass
> that entire functor by value, correct?
 
Yes, copy constructor will be used in the process (unless the compiler is
able to optimize it away, but this probably does not happen here).
legalize+jeeves@mail.xmission.com (Richard): Apr 30 07:01PM

[Please do not mail me a copy of your followup]
 
Doug Mika <dougmmika@gmail.com> spake the secret code
>(along with implementation of operator()) that is passed by value, and
>that if I have a copy constructor implemented, it will be used to pass
>that entire functor by value, correct?
 
Correct. If you don't implement the copy constructor, the compiler
supplies one that does simple member-by-member assignment.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Apr 30 07:02PM

[Please do not mail me a copy of your followup]
 
Paavo Helde <myfirstname@osa.pri.ee> spake the secret code
>> call the oprator() 10 times!
 
>Change this line to:
 
>Result = for_each(vecIntegers.begin(),vecIntegers.end(),Result);
 
Nice! I usually forget about the return value of for_each.
Honestly though, range-based for loops in C++11 I don't expect I'll
be using for_each much, even with lambdas.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 30 03:12PM -0400

On 4/30/2015 3:01 PM, Richard wrote:
>> that entire functor by value, correct?
 
> Correct. If you don't implement the copy constructor, the compiler
> supplies one that does simple member-by-member assignment.
 
Nit-pick: ".. that does simple member-by-member copy construction."
 
V
--
I do not respond to top-posted replies, please don't ask
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Fw: Fwd: 《 河西走廊》

 


On Thursday, April 30, 2015 2:01 AM, Hsiao-Hung <k6hsi@aol.com> wrote:



《 河西走廊》



此集方出佳評如潮每集僅需三刻值得看完......
自西汉張骞出使西域以來2000多年的历史至今開拓的新絲路...
今巳克服甘肅天險---河西走廊----走向西方中亞----直指欧洲----
 
這是今年三月初發布的關於 ' 河西走廊的歷史 ( 始於漢武帝 ), 地理 , 考古 , 風景 ' 的影集 , 每集約 45 分鐘  
------------- -------------------------------
 
 





Digest for comp.lang.c++@googlegroups.com - 25 updates in 5 topics

Doug Mika <dougmmika@gmail.com>: Apr 30 09:45AM -0700

I have the following short program:
 
#include<algorithm>
#include<iostream>
#include<vector>
#include<list>
 
using namespace std;
 
template<typename T>
void FuncDisplayElement(const T& element){
cout<<element<<' ';
}
 
template<typename T>
struct DisplayElement{
void operator()(const T& element) const{
cout<<element<<' ';
}
};
 
 
int main(int argc, char** argv) {

//The Program
vector<int> vecIntegers;

for(int nCount=0;nCount<10; ++nCount)
vecIntegers.push_back(nCount);

list<char> listChars;

for(char nChar='a'; nChar<'k'; ++nChar)
listChars.push_back(nChar);

DisplayElement<int> de;

cout<<"Displaying the vector of integers"<<endl;
for_each(vecIntegers.begin(),vecIntegers.end(),de);
cout<<endl<<endl;

cout<<"Displaying the vector of integers again"<<endl;
for_each(vecIntegers.begin(),vecIntegers.end(),FuncDisplayElement<int>);
cout<<endl<<endl;

cout<<"Displaying the list of characters"<<endl;
for_each(listChars.begin(),listChars.end(),DisplayElement<char>());


return 0;
}
 
My question is, why do I need to include the brakets "()" in:
DisplayElement<char>()
 
when I don't include them in:
de
???
 
DisplayElement<char> creates an rvalue object of that type, so it is now similar to de, so why the brackets in one but not the other?
"Öö Tiib" <ootiib@hot.ee>: Apr 30 10:05AM -0700

On Thursday, 30 April 2015 19:46:07 UTC+3, Doug Mika wrote:
> }
 
> My question is, why do I need to include the brakets "()" in:
> DisplayElement<char>()
 
Because 'DisplayElement<char>' is type while 'DisplayElement<char>()'
makes temporary object of that type.
 
> when I don't include them in:
> de
> ???
 
The 'de' in your code is named object of type 'DisplayElement<int>'.
 
If you want it to be type 'DisplayElement<int>' then you have
to declare it like:
 
typedef DisplayElement<int> de;
 
or in C++11
 
using de = DisplayElement<int>;

On such cases you need to have brackets with de as well.
 
> DisplayElement<char> creates an rvalue object of that type, so it
> is now similar to de, so why the brackets in one but not the other?
 
Where you take that? Not in C++. 'DisplayElement<char>' is just a
type-id like 'int'. You can't use type where object is expected. The
'FuncDisplayElement<int>' is a pointer to function (so object),
'de' is also already existing object and so you need
'DisplayElement<char>()' to create object if you want to pass it
where object belongs in C++.
legalize+jeeves@mail.xmission.com (Richard): Apr 30 05:22PM

[Please do not mail me a copy of your followup]
 
Doug Mika <dougmmika@gmail.com> spake the secret code
 
>My question is, why do I need to include the brakets "()" in:
>DisplayElement<char>()
 
DisplayElement<char> is a type.
 
DisplayElement<char>() is an anonymous temporary instance of the type.
 
>when I don't include them in:
>de
 
This is a named instance of the type.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Doug Mika <dougmmika@gmail.com>: Apr 30 10:33AM -0700

well, that's what I thought, but then how can I explain it with the fact that when we have a class with a default (parameterless) constructor, say the class name is Human, I instantiate the class Human on the stack without the use of brackets:
 
Human someHoman;
 
NOT
Human someHuman();
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 30 01:41PM -0400

On 4/30/2015 1:33 PM, Doug Mika wrote:
> well, that's what I thought, but then how can I explain it with the
fact that when we have a class with a default (parameterless)
constructor, say the class name is Human, I instantiate the class Human
on the stack without the use of brackets:
 
> Human someHoman;
 
> NOT
> Human someHuman();
 
Read up on "most vexing parse".
 
You *declare* a variable of type T by writing
 
T <nameofthevariable>;
 
That's a declaration statement. Depending on the scope in which it
appears it can also be a definition. Definition of an object implies
initialization. Parentheses shift the meaning of the declaration a tiny
bit (again, read up on declaration parsing and it's actually in the FAQ).
 
V
--
I do not respond to top-posted replies, please don't ask
Doug Mika <dougmmika@gmail.com>: Apr 30 11:00AM -0700

On Thursday, April 30, 2015 at 12:42:09 PM UTC-5, Victor Bazarov wrote:
 
> V
> --
> I do not respond to top-posted replies, please don't ask
 
That sort of clears things up. But then, when I declare the anonymous object using:
DisplayElement<int>()
 
am I declaring it on the stack or the heap? And when and by whom is it deleted?
"Öö Tiib" <ootiib@hot.ee>: Apr 30 11:03AM -0700

On Thursday, 30 April 2015 20:33:49 UTC+3, Doug Mika wrote:
> well, that's what I thought, but then how can I explain it with the fact that when we have a class with a default (parameterless) constructor, say the class name is Human, I instantiate the class Human on the stack without the use of brackets:
 
> Human someHoman;
 
If 'Human' is aggregate (without constructors like DisplayElement<int> is)
then function-local 'someHoman' will be uninitialized variable, it won't
be default constructed. Since 'DisplayElement<int>' is stateless (does not
have non-static data members) it does not matter to it, but generally it
matters.
 
> NOT
> Human someHuman();
 
That is function declaration in C++.
When Human is of aggregate type then you need to write:
 
Human someHaman = Human();
 
or:
 
Human someHeman = {};
 
or since C++11:
 
Human someHiman{};
 
to get it default-initialized.
"Öö Tiib" <ootiib@hot.ee>: Apr 30 11:15AM -0700

On Thursday, 30 April 2015 21:00:42 UTC+3, Doug Mika wrote:
 
> That sort of clears things up. But then, when I declare the anonymous object using:
> DisplayElement<int>()
 
> am I declaring it on the stack or the heap? And when and by whom is it deleted?
 
C++ standard does say "automatic storage" (that is usually stack) and
"dynamic storage" (that is usually heap). It does not specify if
temporaries are stored in either (but usually it is stack as well).
Temporary will be destroyed at the end of full expression unless you
initialize reference variable with it. If you initialize reference
variable with it then it will be destroyed when that variable leaves
scope.
legalize+jeeves@mail.xmission.com (Richard): Apr 30 03:05PM

[Please do not mail me a copy of your followup]
 
David Brown <david.brown@hesbynett.no> spake the secret code
 
>No, MSVC has always been notoriously bad at standard C. It barely
>implements the language parts of C99, and until only a couple of years
>ago, it was missing substantial parts of the C99 library.
 
OK, I'll take your word for it on that. Honestly, I haven't written
*C* code since the early 1990s and I really don't want to go back to
writing C code having used C++ all this time.
 
>For C++, I
>believe it is only a few years behind the mainstream (gcc, llvm, Intel)
>- but I haven't used it myself for quite some time.
 
VS2013 is quite current and VS2015 is filling in more of the C++11/14
gaps, certainly when compared to the gcc that ships with enterprise
linux distributions. (I know, you can always build your own gcc to get
around that, but at a big linux shop where I worked for the past 4 years
we were stuck with the lowest common denominator among all distributions
which left us with gcc 4.2.1 and the irony that our Windows build had
access all the modern features, but our linux build did not.)
 
The whole compiler landscape has changed with C++11/14; compiler
implementations are not only keeping up with the standard, they are
often ahead of the standard by implementing C++14/17 features from
working drafts before they are officially adopted. Things are moving
much faster now than they have previously.
 
I believe this table is a pretty accurate comparison:
<http://en.cppreference.com/w/cpp/compiler_support>
If it's not, please edit the table to be more accurate :-).
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
David Brown <david.brown@hesbynett.no>: Apr 30 05:19PM +0200

On 30/04/15 17:05, Richard wrote:
 
> OK, I'll take your word for it on that. Honestly, I haven't written
> *C* code since the early 1990s and I really don't want to go back to
> writing C code having used C++ all this time.
 
I write C all the time, but for embedded systems rather than PC's. But
comp.lang.c has plenty of unpleasant things to say about MSVC for C.
 
> we were stuck with the lowest common denominator among all distributions
> which left us with gcc 4.2.1 and the irony that our Windows build had
> access all the modern features, but our linux build did not.)
 
Since I work with cross-compilers most of the time, I don't see such
issues - I don't make much use of native compilers. But some shops have
very restrictive rules on the tools that developers are allowed to use -
for good reasons or for bad reasons.
 
> often ahead of the standard by implementing C++14/17 features from
> working drafts before they are officially adopted. Things are moving
> much faster now than they have previously.
 
It makes a nice change - especially since C++11 brought in so many
useful features, and C++14 improves them.
 
legalize+jeeves@mail.xmission.com (Richard): Apr 30 03:21PM

[Please do not mail me a copy of your followup]
 
David Brown <david.brown@hesbynett.no> spake the secret code
 
>Or mingw-w64 and an IDE (Eclipse, Code Blocks, JEdit, etc. - or even
>emacs or vim).
 
emacs? If I want to time travel to 1990, it's fine. I used it from
1988 through 1998. It's an editor with a keyboard shortcut to invoke
a build, not really an IDE.
 
vim? Some people swear by it with the multiple windows and whatnot
that are in vim (not classic vi). It might be usable with all the
doodads and extensions on top, but a good IDE is much more than an
editor. I haven't tried a vim-ified experience, but if you're using
it only as classic vi experience, then it's only good for small
projects in my opinion. I used it for editing code from 1978-ish
through 1988. I still use daily for editing email. I don't use it
for editing anything other than small "will this compile?" type
programs.
 
JEdit seems to be an editor and not an IDE.
 
Eclipse? God no, please don't. Go use CLion from JetBrains instead.
In fact, always prefer something from JetBrains over Eclipse. For
Java it simply blows Eclipse out of the water. Yes, JetBrains IDEs
are commercial, but if you're working on open source, ask for a free
license and you'll probably get one.
 
Code Blocks (Code::Blocks?) is on my list of IDEs to try, but I
haven't yet.
 
If your environment doesn't actually parse C++ to give you
semantically meaningful navigation (oops, that cuts out ctags and
therefore vim and emacs as well), refactoring (oops, that cuts out any
editor), an intelligent debugger (oops, that cuts out editors) and
so-on, then it's not an IDE. It's an editor with keyboard shortcuts
to invoke other programs to make up for its deficiencies as an IDE.
The "I" (integrated) in IDE really is important.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Christopher Pisz <nospam@notanaddress.com>: Apr 30 11:23AM -0500

On 4/30/2015 10:21 AM, Richard wrote:
SNIP
 
> Java it simply blows Eclipse out of the water. Yes, JetBrains IDEs
> are commercial, but if you're working on open source, ask for a free
> license and you'll probably get one.
 
How does CLion measure up to Msvc if one intends to solely write code on
Windows? Is there any advantage to it? Is it difficult to find all the
common windows libs and such, like the winsock lib? Come with them?
 
I see the price tag is lower for an individual license and Intellisense
has really been pissing me off lately.
 
Or would it be more for a person who is writing code for multiple platforms?
 
 
 
--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---
"Öö Tiib" <ootiib@hot.ee>: Apr 30 09:50AM -0700

On Thursday, 30 April 2015 18:21:45 UTC+3, Richard wrote:
> Code Blocks (Code::Blocks?) is on my list of IDEs to try, but I
> haven't yet.
 
From general purpose IDEs NetBeans understands and highlights C++ lot
better than Code Blocks and tools seem also easier to integrate to it.
 
If you want to design for iPad or iPhone then you need Apple Xcode
that is otherwise not too good IDE. If you want to try Qt then it
is easiest with Qt Creator that is passable for IDE.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 01:12PM -0500

legalize+jeeves@mail.xmission.com (Richard) wrote in news:mhth9u$11t$2
 
> Code Blocks (Code::Blocks?) is on my list of IDEs to try, but I
> haven't yet.
 
IMO you have not lost anything. My list of complaints about C::B is so long
I cannot even start.
Doug Mika <dougmmika@gmail.com>: Apr 30 10:38AM -0700

When I ran the following program:
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
 
template<typename T>
struct DisplayElementKeepCount{
int Count;

DisplayElementKeepCount():Count(0){}

void operator()(const T& element){
++Count;
cout<<element<<' ';
}
};
 
int main(int argc, char** argv) {
 
//The Program
vector<int> vecIntegers;

for(int nCount=0;nCount<10; ++nCount)
vecIntegers.push_back(nCount);

DisplayElementKeepCount<int> Result;

cout<<"Displaying the vector of integers again"<<endl;
for_each(vecIntegers.begin(),vecIntegers.end(),Result);
cout<<endl<<endl;

cout<<"The Result count this time is: "<<Result.Count<<endl;


return 0;
}
 
the result of Result.Count is 0!!!, WHY isn't it 10????? Afterall, I call the oprator() 10 times!
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 30 01:47PM -0400

On 4/30/2015 1:38 PM, Doug Mika wrote:
 
> DisplayElementKeepCount<int> Result;
 
> cout<<"Displaying the vector of integers again"<<endl;
> for_each(vecIntegers.begin(),vecIntegers.end(),Result);
 
Right here the 'Result' is not used directly, but *copied* into the
argument of 'for_each' function. Inside you're incrementing the 'Count'
member of the copy. The outside object is unchanged.
 
 
> return 0;
> }
 
> the result of Result.Count is 0!!!, WHY isn't it 10????? Afterall, I call the oprator() 10 times!
 
Yes, but for which object? Display the 'this' pointer in your
'operator()' and compare it to the address of 'Result' variable.
 
V
--
I do not respond to top-posted replies, please don't ask
legalize+jeeves@mail.xmission.com (Richard): Apr 30 05:49PM

[Please do not mail me a copy of your followup]
 
Doug Mika <dougmmika@gmail.com> spake the secret code
>}
 
>the result of Result.Count is 0!!!, WHY isn't it 10????? Afterall, I
>call the oprator() 10 times!
 
The functor is copied around by for_each, so the one it uses is not
the one that you declared locally, it's a copy. This is implied by
the signature of for_each which takes the functor by value. To get
what you want, you have to use a referring wrapper like boost::ref, or
have your functor reference the count held elsewhere:
 
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
 
template<typename T>
struct DisplayElementKeepCount{
int &Count;
 
DisplayElementKeepCount(int &Storage):Count(Storage){}
 
void operator()(const T& element){
++Count;
cout<<element<<' ';
}
};
 
int main(int argc, char** argv) {
 
//The Program
vector<int> vecIntegers;
 
for(int nCount=0;nCount<10; ++nCount)
vecIntegers.push_back(nCount);
 
int Count = 0;
DisplayElementKeepCount<int> Result(Count);
 
cout<<"Displaying the vector of integers again"<<endl;
for_each(vecIntegers.begin(),vecIntegers.end(),Result);
cout<<endl<<endl;
 
cout<<"The Result count this time is: "<<Result.Count<<endl;
 
 
return 0;
}
 
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Joseph Hesse <joeh@gmail.com>: Apr 30 12:03PM -0500

Hello,
 
In C++ 11, why can't I write:
 
enum class Values = {1, 2, 3};
 
Thank you,
Joe
Joseph Hesse <joeh@gmail.com>: Apr 30 12:05PM -0500

Hello,
 
In C++ 11, why can't I write:
 
enum class Values = {1, 2, 3};
 
I want to treat 1 as a symbol with no meaning.
 
Thank you,
Joe
"Öö Tiib" <ootiib@hot.ee>: Apr 30 10:14AM -0700

On Thursday, 30 April 2015 20:05:17 UTC+3, Joseph Hesse wrote:
 
> In C++ 11, why can't I write:
 
> enum class Values = {1, 2, 3};
 
> I want to treat 1 as a symbol with no meaning.
 
Unfortunately to you C++ language has already given a meaning
to 1. It is integer constant that is often named "one" in English.
You are not allowed to modify that meaning by C++ language rules.
legalize+jeeves@mail.xmission.com (Richard): Apr 30 05:23PM

[Please do not mail me a copy of your followup]
 
Joseph Hesse <joeh@gmail.com> spake the secret code
 
>I want to treat 1 as a symbol with no meaning.
 
1 is not a symbol; it is an integer literal.
 
A symbol is an identifier and must follow the rules for identifiers in C++.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Juha Nieminen <nospam@thanks.invalid>: Apr 30 02:27PM

Consider this:
 
//------------------------------------------------------------------------
template<typename T> void foo(const T&) { std::printf("Generic\n"); }
template<> void foo(const char* const&) { std::printf("const char*\n"); }
 
int main()
{
foo(12);
foo("abc");
const char* str = "abc";
foo(str);
}
//------------------------------------------------------------------------
 
It prints:
 
Generic
Generic
const char*
 
What would be the best way to specialize a template for string literals?
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
simont <s_j_turner@yahoo.co.uk>: Apr 30 08:24AM -0700

On Thursday, April 30, 2015 at 3:27:49 PM UTC+1, Juha Nieminen wrote:
> Generic
> const char*
 
> What would be the best way to specialize a template for string literals?
 
You could just stop trying to pass them by reference, so pointer decay works normally:
 
template<typename T> void foo(T) { std::printf("Generic\n"); }
template<> void foo(const char*) { std::printf("const char*\n"); }
 
or add
 
template<size_t N> void foo(const char (&)[N]) { std::printf("const char [%u]\n", N); }
 
if you want to differentiate between arrays and const char *.
I don't think there's a bulletproof way to distinguish between literals and
copy-initialized arrays, though.
 
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 30 11:25AM -0400

On 4/30/2015 10:27 AM, Juha Nieminen wrote:
> Generic
> const char*
 
> What would be the best way to specialize a template for string literals?
 
String literals are arrays of char, which do decay to pointers but not
for the purpose of type deduction. I think you should be able to make
this work:
 
template<typename T> void foo(const T&) { std::printf("Generic\n"); }
template<int n> void foo(const char(&)[n])
{ std::printf("array of const char\n"); }
 
int main()
{
foo(12);
foo("abc");
const char* str = "abc";
foo(str);
}
 
The problem, of course, is that literals of different lengths the
compiler will instantiate all different 'foo<n>' variations. You could
try to involve inheritance to unify those.
 
V
--
I do not respond to top-posted replies, please don't ask
guinness.tony@gmail.com: Apr 30 08:31AM -0700

On Thursday, 30 April 2015 15:27:49 UTC+1, Juha Nieminen wrote:
> Generic
> const char*
 
> What would be the best way to specialize a template for string literals?
 
template<size_t N>
void foo(const char(&)[N]) { std::printf("const char(&)[]\n"); }
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Wednesday, April 29, 2015

Digest for comp.lang.c++@googlegroups.com - 12 updates in 4 topics

Paavo Helde <myfirstname@osa.pri.ee>: Apr 28 11:56PM -0500

legalize+jeeves@mail.xmission.com (Richard) wrote in
 
> Please god, no.
 
> IMO, cygwin/mingw is a giant PITA on Windows and there isn't any need
> for it.
 
Cygwin is fine for getting a bunch of decent Unix tools working on Windows.
For developing unrelated software, not so much.
David Brown <david.brown@hesbynett.no>: Apr 29 09:08AM +0200

On 29/04/15 06:56, Paavo Helde wrote:
>> for it.
 
> Cygwin is fine for getting a bunch of decent Unix tools working on Windows.
> For developing unrelated software, not so much.
 
Talking about cygwin/mingw is like talking about C/C++ - they are
different things, with a certain overlap and common history.
 
Cygwin was used a lot in the past as a way to get *nix software and
tools running on Windows - it emulates most of posix. It has the
disadvantages of being big, bulky, slow, and feeling "alien" in Windows
(plus not everyone likes the licensing terms).
 
Mingw provides a much smaller wrapper to make Windows look a bit more
posix-like, but without covering everything. (As an example, cygwin
provides "fork", even though it is very expensive to implement on
Windows. mingw is limited to "spawn" which is much faster and less
obtrusive. Mingw also lets you work with filenames and directories in
Windows style, rather than converting them to a bastardisation between
*nix and Windows.)
 
Mingw is a perfectly good toolchain for Windows - it's C support
(especially for the Mingw-w64 variant) is far superior to MS' tools.
And msys (or now msys2) is a solid set of *nix tools and command-line
utilities that are efficient and fit well with the rest of Windows.
 
But if you need to compile *nix software unchanged on Windows, then
cygwin might be the only way to do it.
legalize+jeeves@mail.xmission.com (Richard): Apr 29 03:29PM

[Please do not mail me a copy of your followup]
 
Paavo Helde <myfirstname@osa.pri.ee> spake the secret code
 
>Cygwin is fine for getting a bunch of decent Unix tools working on Windows.
>For developing unrelated software, not so much.
 
Agreed. If what you want is sed/awk/grep, then by all means get cygwin.
 
If what you want is a C++ development environment, then get VS
community edition.
 
I am very comfortable and productive with the command-line, but I first
used a C++ IDE (VC6) in the late 1990s and now I don't want to go back
to the primitive tools of the unix command-line for building, writing,
editing, and debugging C++ code. (I'm OK with writing CMakeLists.txt,
because cmake operates at a higher level than make.)
 
I found myself much more productive using an IDE. Until recently, the
best IDE for C++ development was Visual Studio, but with the release
of CLion, it has a serious challenger. There are some things I like
about both; CLion has a much faster feel than VS for navigating,
editing and writing C++ code. VS has a truly awesome debugger. It
makes gdb look like the early 1990s immitation of dbx that it is. VS
has a better docking system than CLion. CLion has better refactoring
support, although I haven't yet tried the VS2015 refactoring support.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Apr 29 03:33PM

[Please do not mail me a copy of your followup]
 
David Brown <david.brown@hesbynett.no> spake the secret code
 
>Mingw is a perfectly good toolchain for Windows - it's C support
>(especially for the Mingw-w64 variant) is far superior to MS' tools.
 
I think you're confusing C with POSIX here. They aren't the same thing.
The POSIX implementation in MSVC has always been weak, although
apparently they're finally getting around to plugging some of the
holes in VS 2015.
 
>But if you need to compile *nix software unchanged on Windows, then
>cygwin might be the only way to do it.
 
I agree with this because you said "unchanged". I've been dealing
with system differences between unix implementations for decades and
most of the time, dealing with the differences isn't a huge deal,
although it is annoying. That's the whole reason people have
configure scripts and the whole mess that is autotools and so-on.
Personally I find CMake's approach to the problem better than
autotools and it is more portable because it doesn't depend on bash or
perl or python or whatever.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
David Brown <david.brown@hesbynett.no>: Apr 29 11:30PM +0200

On 29/04/15 17:33, Richard wrote:
> The POSIX implementation in MSVC has always been weak, although
> apparently they're finally getting around to plugging some of the
> holes in VS 2015.
 
No, MSVC has always been notoriously bad at standard C. It barely
implements the language parts of C99, and until only a couple of years
ago, it was missing substantial parts of the C99 library. For C++, I
believe it is only a few years behind the mainstream (gcc, llvm, Intel)
- but I haven't used it myself for quite some time.
 
Posix support is an issue for Windows and translation layers (like
cygwin, or the much smaller and thinner layers in mingw libraries) - and
despite promises when NT was new, Windows has never tried to support
posix properly.
 
> Personally I find CMake's approach to the problem better than
> autotools and it is more portable because it doesn't depend on bash or
> perl or python or whatever.
 
Indeed - autotools is not an efficient or pleasant system in my
(limited) experience. But if you need to use it for something, then
cygwin is the way to go for the greatest compatibility. When I first
compiled a gcc cross-compiler on Windows, cygwin was the only "easy"
option - but for many years it's been possible (and /much/ faster and
easier) with mingw.
David Brown <david.brown@hesbynett.no>: Apr 29 11:34PM +0200

On 29/04/15 17:29, Richard wrote:
 
>> Cygwin is fine for getting a bunch of decent Unix tools working on Windows.
>> For developing unrelated software, not so much.
 
> Agreed. If what you want is sed/awk/grep, then by all means get cygwin.
 
No, get msys (or now msys2), which includes these tools compiled with
mingw. They are faster, and a lot easier to use along with other
Windows stuff.
 
Only use cygwin if you need fork() and other "tougher" posix calls.
 
 
> If what you want is a C++ development environment, then get VS
> community edition.
 
Or mingw-w64 and an IDE (Eclipse, Code Blocks, JEdit, etc. - or even
emacs or vim).
 
> makes gdb look like the early 1990s immitation of dbx that it is. VS
> has a better docking system than CLion. CLion has better refactoring
> support, although I haven't yet tried the VS2015 refactoring support.
 
There's nothing wrong with using an IDE - but MSVS is not the only
option for an IDE on Windows.
drew@furrfu.invalid (Drew Lawson): Apr 29 04:45PM

In article <D9GdnRDo_MGucqLInZ2dnUU7-cednZ2d@giganews.com>
 
>What the fuck are you doing mate? Exceptions should be thrown rarely not
>routinely (mainly for exceptional conditions) so who cares about bloody
>string allocations?
 
I share that view, but not everyone does. A couple jobs back, I
was in an organization where exceptions were the preferred response
to almost everything. If a request was not a pure, unqualified,
success, the server threw an exception. Some parts would make a
request, catch the exception, change the request parameters, throw
a "try again" exception, catch that further up the stack, and then
resubmit the request.
 
Probably 1/4 of the application was try/catch blocks. Drove me
crazy, especially trying to find where in that flow to make an
otherwise simple change.
 
 
--
Drew Lawson | Radioactive cats have
| 18 half-lives
|
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Apr 29 10:11PM +0100

On Tue, 28 Apr 2015 15:01:11 -0700 (PDT)
> Leigh, please don't swear here.
 
I wish you could get it into your somewhat curious system of reasoning
that "fuck" is not swearing. It is bad language (for some of the more
fastidious at least, personally I couldn't care a fuck).
 
Swearing is an offence to your god. Bad language is an offence to man.
 
Chris
Jorgen Grahn <grahn+nntp@snipabacken.se>: Apr 29 07:24PM

On Tue, 2015-04-28, Stefan Ram wrote:
> about the concept »Compare« that I gave might help the
> OP to learn what kind of type is expected in his code,
> and something similar might become part of C++17 or C++2x.
 
The SGI STL documentation from 1998 explains it clearly, too:
 
https://www.sgi.com/tech/stl/List.html
https://www.sgi.com/tech/stl/LessThanComparable.html
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 28 07:49PM -0400

On 4/28/2015 6:44 PM, Marcel Mueller wrote:
 
>> What would your container contain if it only had one element? IOW, what
>> happens when it goes from empty to ??? upon the first insertion?
 
> The first entry gets end().
 
OK, so the first entry makes your map non-empty. In other words, the
map contains one element, and therefore its iterators are now end()
(which is kept in the first element) and the one that is not 'end()',
i.e. the iterator to the "first" entry, whose content is 'end()', yes?
And where is that iterator kept? You seem to immediately need to insert
another element into your map which should contain the iterator to the
first non-end() iterator. That is, your map now contains two entries,
the first of which is 'end()', the other is the iterator of the "real"
element... And so on.
 
> When the second entry is inserted the first
> one is changed to the iterator returned from the second insert and so
> forth.
 
When? And where is the consistency of the map? It will always contain
one element iterator to which is not kept in the same map? 8-O
 
> oldest elements after a specified size has been reached. I only need to
> keep an iterator to the oldest element (head) for removal and one to the
> newest element (tail) for replacing end() of the last entry.
 
What is it you're trying to model with that paradoxical structure? And
why a map? If you need a circular buffer, find and use a circular
buffer. I am sure there are numerous examples of such an adapter.
 
V
--
I do not respond to top-posted replies, please don't ask
"Öö Tiib" <ootiib@hot.ee>: Apr 28 05:32PM -0700

On Wednesday, 29 April 2015 02:49:23 UTC+3, Victor Bazarov wrote:
 
> What is it you're trying to model with that paradoxical structure? And
> why a map? If you need a circular buffer, find and use a circular
> buffer. I am sure there are numerous examples of such an adapter.
 
It feels like when there is
 
std::array<Something,SpecifiedSize> insertion_sequence;
 
whose elements can be same time also in
 
boost::intrusive::multiset<Something> lookup_set;
 
So he can O(log SpecifiedSize) find an element by some criteria from
the sequence instead of O(SpecifiedSize).
"K. Frank" <kfrank29.c@gmail.com>: Apr 29 11:50AM -0700

Hello Marcel!
 
You raise a very interesting question (for which I don't
have a clean answer).
 
On Tuesday, April 28, 2015 at 4:16:47 PM UTC-4, Marcel Mueller wrote:
 
> The iterators are required to maintain a second independent sort order,
> that only needs a linked list because it only requires the operations
> pop_front and push_back.
 
Without going into why you might want to do this or
whether it would be a good idea, I do think you raise
a very interesting general point.
 
In the "old days" you might do something like:
 
typedef struct Element { Element* pElement; } element_type;
typedef element_type collection_type[30];
 
This is a very standard usage, purposely supported
by the language, and used, e.g., by the classic linked
list.
 
This works because you can use pointers to incomplete
types. (You can also forward-declare incomplete types.)
 
Now one aspect of iterators is that they are abstractions
or generalizations of pointers. So you raise the very
natural question of how or whether the same thing might
be done with iterators.
 
As far as I know, you can't, but I would love to be
shown wrong.
 
Of course, "All problems can be solved by another level
of indirection." So you could do something like:
 
#include <map>
using std::multimap;
 
struct iterator_wrapper;
 
typedef int key_type;
typedef iterator_wrapper* element_type;
typedef multimap<key_type, element_type> map_type;
typedef map_type::iterator iterator_type;
 
struct iterator_wrapper { iterator_type it; };
 
This, to my mind, has two imperfections: Iterators are
already a form of indirection, so the extra level of
indirection -- element_type is a pointer -- seems
conceptually unnecessary, and could add a little cost.
 
Also, while adding no run-time cost, the need to wrap
the iterator in iterator_wrapper (I don't see any way
to avoid this.) seems unfortunate.
 
Your desired use case illustrates a feature of pointers
that iterators do NOT provide. Would it make sense for
the language / standard library to provide such functionality
for iterators? (And would it be possible, given that
standard-library collections are templates?)
 
> Marcel
 
 
Best regards.
 
 
K. Frank
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.