Wednesday, April 1, 2009

comp.lang.c++ - 25 new messages in 11 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* String with integers? - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/18ba850e8ec017d4?hl=en
* Defining Non-Member Functions for Template Member Types - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/b03b7e975705740e?hl=en
* Handling large text streams of integers - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/5ef7335840714596?hl=en
* What is the correct template syntax for this? - 9 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/01e2a40e6b1406d3?hl=en
* Pruning a std::map efficiently? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/f45ae8609ee5b84c?hl=en
* boost::array< pair<>, maxsize >::iterator and adaptor - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/2ae60ced74e9c45a?hl=en
* computer - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/fd903a7c5c0d039c?hl=en
* Inheritance: Implementing pure virtual functions by inheriting from an
object providing an implementation - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/93aaba3f11367deb?hl=en
* Eclipse & include file - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/03855515fb3c1bbf?hl=en
* Seeking Enthusiasts of Oil Paintings and Frames Worldwide - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/2d8d9e1cdefa2598?hl=en
* PORTING Applications from 32 bit to 64 bit Architecture - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/3fc395032a4427d0?hl=en

==============================================================================
TOPIC: String with integers?
http://groups.google.com/group/comp.lang.c++/t/18ba850e8ec017d4?hl=en
==============================================================================

== 1 of 5 ==
Date: Tues, Mar 31 2009 11:58 pm
From: "wp8088"


fair enough there you are

#include <cstdlib>
#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
int i = 42;
ostringstream ss;
ss << i;
string str = ss.str();
system("PAUSE");
return EXIT_SUCCESS;
}

"mlt" <asdf@asd.com> wrote in message
news:49d2821d$0$90267$14726298@news.sunsite.dk...
> In java an int can be included in a string like:
>
> String str = ""+33 + "strings";
>
> In c++ I have only found:
>
> std::string str = "test";
> std::stringstream out;
> out << 222;
> str = str + out.str();
>
> Is that really the only way to do this in C++?
>
>
>
>
>


== 2 of 5 ==
Date: Wed, Apr 1 2009 12:15 am
From: Jorgen Grahn


On Tue, 31 Mar 2009 22:50:22 +0200, mlt <asdf@asd.com> wrote:
> In java an int can be included in a string like:
>
> String str = ""+33 + "strings";
>
> In c++ I have only found:
>
> std::string str = "test";
> std::stringstream out;
> out << 222;
> str = str + out.str();
>
> Is that really the only way to do this in C++?

It looks better when you rewrite it without operator+ :

std::stringstream out;
out << "test" << 222;
// use out.str();

You might also find that what you really want to do with the string is
to place it on a stream, so you can skip the intermediate string.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!


== 3 of 5 ==
Date: Wed, Apr 1 2009 1:15 am
From: James Kanze


On Mar 31, 10:50 pm, "mlt" <a...@asd.com> wrote:
> In java an int can be included in a string like:

> String str = ""+33 + "strings";

Which is a nice source of errors, and a serious design flaw.

> In c++ I have only found:

> std::string str = "test";
> std::stringstream out;
> out << 222;
> str = str + out.str();

> Is that really the only way to do this in C++?

Yep. Strings are not formatters; formatting is done by
ostream. In Java, of course, if you want to do it right,
and avoid confusion and maintenance problems, you use
java.text.Format. (The basic problem, of course, is that
there are many valid conversions of an int to a string. In
anything but toy programs, you generally have to specify
some of the details.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


== 4 of 5 ==
Date: Wed, Apr 1 2009 1:20 am
From: James Kanze


On Apr 1, 1:26 am, Vladyslav Lazarenko <vlazare...@volanttrading.com>
wrote:

> It looks like we forgot about Boost.Format. Example:

> int i = 1986;
> const char s[] = "STR";

> std::string res = boost::str(boost::format("This is my number: %1%.
> This is my string: %2%") % i % s);

The problem is that the use of '%' as both the operator and
the format specifier very quickly leads to unreadable
expressions (not to mention the fact that the precedence of
% is wrong). The standard library's choice of << here is
about the best you can do if you insist on an operator; a
better solution would be to use a named function, or even an
operator(), e.g.:

std::string res( Format(
"This is my number: %1%. This is my string: %2%" )
.with( i )
.with( s )
.str() ) ;

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


== 5 of 5 ==
Date: Wed, Apr 1 2009 1:24 am
From: "Alf P. Steinbach"


* James Kanze:
> On Mar 31, 10:50 pm, "mlt" <a...@asd.com> wrote:
>> In java an int can be included in a string like:
>
>> String str = ""+33 + "strings";
>
> Which is a nice source of errors, and a serious design flaw.
>
>> In c++ I have only found:
>
>> std::string str = "test";
>> std::stringstream out;
>> out << 222;
>> str = str + out.str();
>
>> Is that really the only way to do this in C++?
>
> Yep. Strings are not formatters; formatting is done by
> ostream. In Java, of course, if you want to do it right,
> and avoid confusion and maintenance problems, you use
> java.text.Format. (The basic problem, of course, is that
> there are many valid conversions of an int to a string. In
> anything but toy programs, you generally have to specify
> some of the details.)

No, the difference between general formatting with zillions of options, and
default simple conversion of an integer to string, is just that, zillions of
options versus default simple.

In some cases you (or perhaps not "you" you, but the generic you) want one, in
other cases the other.

Whether the program is toy or the next Photoshop has nothing to do with it; in
both kinds of program the default simple conversion is the one most often
required, and the zillions-of-options one the one least often required.

And formatting isn't necessarily done by ostream.

The nice thing about C++ is that we can choose, and many choose to not use
iostreams except for -- heh, toy programs. ;-)


Cheers,

- Alf

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!

==============================================================================
TOPIC: Defining Non-Member Functions for Template Member Types
http://groups.google.com/group/comp.lang.c++/t/b03b7e975705740e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 12:37 am
From: James Kanze


On Apr 1, 3:52 am, "Alf P. Steinbach" <al...@start.no> wrote:
> * flounder:
> > The compiler is unable to find a match for the call to
> > munge() and operator==() in is_equal() below. Can someone
> > post an explanation and/ or suggest a workaround?

> > template<class T>
> > struct Foo {
> > struct Bar {};
> > };

> > template<class T>
> > bool operator==(const typename Foo<T>::Bar&, const typename
> > Foo<T>::Bar&);

> > template<class T>
> > void munge(typename Foo<T>::Bar* );

> > inline bool
> > is_equal(Foo<int>::Bar x, Foo<int>::Bar y)
> > {
> > munge(&x);
> > return x == y; // no operator "==" matches these operands
> > }

> I googled.

> See
> <url:http://www.codeguru.com/forum/archive/index.php/t-395268.html>;
> "non-deduced context".

> However while it seems the facts there are OK, the
> rationalization there seems very fishy to me. Perhaps that
> rationalization is the standard's rationale (I'm too lazy to
> check). But in a context like above I see no good reason why
> the language could not have permitted the matching: there can
> be only one match.

The problem is that in the general case, at least, the compiler
would have to verify all of the possible expansions of Foo<>.
Suppose, for example, one of them expanded to contain:
typedef typename Foo<int>::Bar Bar ;
. (That would make the call ambiguous.) It's easy for a human,
looking at the template definition, and knowing that there are
no explicit specializations, to realize that this could not be
the case, but this realization is based on a higher degree of
logic than compilers are capable of.

> I can see a bad reason, though, namely treating all types the
> same way, and the above would indeed be problematic with Bar a
> typedef'ed name, e.g. for 'int'.

Exactly. And you don't know what Bar will be in Foo<T> until
you've instantiated Foo<T>.

The problem is that we humans (most of us, anyway) can think
very well in abstract terms, along the lines of "for all T...".
Machines can't, or at least, current compilers don't incorporate
any technology that can.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

==============================================================================
TOPIC: Handling large text streams of integers
http://groups.google.com/group/comp.lang.c++/t/5ef7335840714596?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 1 2009 12:45 am
From: James Kanze


On Mar 31, 11:54 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> James Kanze wrote:
> > A lot of systems maintain the current position in the file
> > in an std::streamsize. Which means that
> > std::numeric_limits<std::streamsize>::max() is also the
> > maximum number of bytes in the file. And that there can't
> > be that many numbers, since each number requires at least
> > two bytes (one digit and a separator).
> > [..]

> What if the "file" is actually a serial connection that, like
> the Energizer Bunny, just keeps going, and going, and... Will
> the system also try to keep track of the "current position" on
> a socket, for example?

That's actually a good question. I don't know what the standard
says about it---probably that it's unspecified. (The standard
doesn't require the system to try to keep track of the "current
position". But in practice, it has to, in some way, in order to
know where the next data is to come from.) I suspect that in
practice, most systems "try" to keep track of it, in the sense
that they update it each time with the number of bytes read, but
that they fail in the case of something like a socket, pipe, or
keyboard; but that it doesn't matter, because the next data are
determined automatically, and those devices don't support
seeking (which would also require the position).

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


== 2 of 2 ==
Date: Wed, Apr 1 2009 1:09 am
From: James Kanze


On Apr 1, 8:47 am, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Tue, 31 Mar 2009 17:54:27 -0400, Victor Bazarov
> <v.Abaza...@comAcast.net> wrote:
> > James Kanze wrote:
> ...
> >> A lot of systems maintain the current position in the file
> >> in an std::streamsize. Which means that
> >> std::numeric_limits<std::streamsize>::max() is also the
> >> maximum number of bytes in the file. And that there can't
> >> be that many numbers, since each number requires at least
> >> two bytes (one digit and a separator).
> >> [..]

> > What if the "file" is actually a serial connection that,
> > like the Energizer Bunny, just keeps going, and going,
> > and... Will the system also try to keep track of the
> > "current position" on a socket, for example? I know, I
> > know, the OP asked about a text file...

> I am obviously too lazy to check what the standard says about
> std::numeric_limits<std::streamsize>::max(), but I hope it's
> just a case of unfortunate naming and that it has to do with
> seekable streams only (like James hinted at elsewhere).

> I'd be very disappointed if you couldn't use iostreams with
> "infinite streams", which (on Unix) includes pipes, (TCP)
> sockets, /dev/random, ... I expect to be able to use
> std::cin/cerr constantly for years.

Given that the standard doesn't require support for such
things, it doubtlessly doesn't say anything. Disk file
access (even without seek) often does involve the "current
position", at least internally. To quote from the man page
of "read" (the lowest level system function which accesses
the data) on Solaris:

On files that support seeking (for example, a regular
file), the read() starts at a position in the file
given by the file offset associated with fildes. The
file offset is incremented by the number of bytes
actually read.

Files that do not support seeking (for example,
terminals) always read from the current position. The
value of a file offset associated with such a file is
undefined.

But also:

For regular files, no data transfer will occur past the
offset maximum established in the open file description
associated with fildes.

Interally, the system maintains the position as a 64 bit
value. When compiling in 32 bit mode, std::streamsize is 32
bits, and files are opened by default in a mode which only
allows 2^32 as the offset maximum, so the limitation holds.
(The C++ standard library could open the files in a way that
would allow 64 bit seeks and reads, even in 32 bit mode.
I'm pretty sure it doesn't, since we've had problems with
log data being lost when the log file size was greater than
2^32.)

Generally speaking, a lot of systems allow files larger than
2^32 bytes, but compiling in 32 bit mode. In such cases,
several solutions are possible:

-- If the system has two modes for accessing the files,
like Solaris, the library code just uses the 32 bit
mode, and the system behaves as if files couldn't be
bigger than 2^32 bytes. I suspect that this is the most
frequently used solution. (It's certainly the easiest
to implement, if the system supports it, and I suspect
that most systems, or at least most Unix, do.)

-- If the system doesn't have such support, the library
could keep track of the position as well, and simulate
it.

-- Alternatively, the library could either use a 64 bit
type for std::streamsize (if one exists on the
implementation) or define it as a class type, using 2 or
more smaller integral types in the implementation, using
whatever system requests are necessary to support full
64 bit file positionning at the system level. In many
ways, this would be the best solution. But if it means
making std::streamsize a class type, it will probably
break code. Incorrect code, since the standard doesn't
require that std::streamsize be an integral type, or
even that it reasonably convert to one, but such code
exists, and is, I fear, widespread. (If the system
supports long long, as most do now adays,
std::streamsize could be a typedef to this.)

-- Finally, I'm sure that some libraries just ignore the
issue. If the system defaults to limiting the file size
to 2^32 in 32 bit code, this is identical to the first
case above. If it doesn't, then the library isn't
conform---std::istream::tellg can return an apparently
valid position, but seeking to it will not go to the
right place. Still, conform or not, it wouldn't
surprise me to encounter such a system.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

==============================================================================
TOPIC: What is the correct template syntax for this?
http://groups.google.com/group/comp.lang.c++/t/01e2a40e6b1406d3?hl=en
==============================================================================

== 1 of 9 ==
Date: Wed, Apr 1 2009 12:51 am
From: fabio_cannizzo@yahoo.com


The following syntax cause gcc to complain about:
- explicit specialization in non-namespace scope
- enclosing class templates are not explicitly specialized

So I guess that I need to put the specialization of foo<0> somewhere
out of the class definition, but what is the correct syntax to do
that?

Thanks a lot

template <class A>
class MyClass
{
template <unsigned char N>
void foo( sie_t int ) { /* ... */ }

template <>
void foo<0>( sie_t int ) { /* ... */ }
};

== 2 of 9 ==
Date: Wed, Apr 1 2009 2:00 am
From: fabio_cannizzo@yahoo.com


In the previous messages there where a few typo. I rewrote better the
code:

template <class A>
class MyClass
{
template <unsigned char N>
void foo( int x )
{
// ... do something
foo<N-1>( x );
}

template <>
void foo<0>( int x )
{
// do nothing: stops template expansion recursion
}
};


== 3 of 9 ==
Date: Wed, Apr 1 2009 3:27 am
From: SG


On 1 Apr., 09:51, fabio_canni...@yahoo.com wrote:
> The following syntax cause gcc to complain about:
> - explicit specialization in non-namespace scope
> - enclosing class templates are not explicitly specialized
>
> So I guess that I need to put the specialization of foo<0> somewhere
> out of the class definition, but what is the correct syntax to do
> that?

Yes. Have you tried the namespace scope? :-p

struct S
{
template<int N>
void foo(int k);
};

template<int N>
void S::foo(int k) {}

template<>
void S::foo<0>(int k) {}


Cheers!
SG


== 4 of 9 ==
Date: Wed, Apr 1 2009 3:37 am
From: ZikO


SG wrote:
> Yes. Have you tried the namespace scope? :-p
>
> struct S
> {
> template<int N>
> void foo(int k);
> };
>
> template<int N>
> void S::foo(int k) {}
>
> template<>
> void S::foo<0>(int k) {}
>
>
> Cheers!
> SG

Is this also possible for the template function in the template class ?

Cheers!
ZikO


== 5 of 9 ==
Date: Wed, Apr 1 2009 3:52 am
From: SG


On 1 Apr., 12:37, ZikO <ze...@op.pl> wrote:
> SG wrote:
> > Yes. Have you tried the namespace scope? :-p
>
> >   struct S
> >   {
> >      template<int N>
> >      void foo(int k);
> >   };
>
> >   template<int N>
> >   void S::foo(int k) {}
>
> >   template<>
> >   void S::foo<0>(int k) {}
>
> > Cheers!
> > SG
>
> Is this also possible for the template function in the template class ?

You mean "function template" and "class template". The answer is
yes. It's something along the lines of

template<typename T>
template<int N>
void S<T>::foo(int k) {}

template<typename T>
template<>
void S<T>::foo<0>(int k) {}


Cheers!
SG


== 6 of 9 ==
Date: Wed, Apr 1 2009 4:23 am
From: fabio_cannizzo@yahoo.com


I tried what suggested in SG's mail, but did not work.

I think specialization of method is not allowed.

Anyway, since the class had not that many members, I changed my design
putting the second template argument in the outer class. Then it
became easy to specialise it.

== 7 of 9 ==
Date: Wed, Apr 1 2009 4:37 am
From: ZikO


SG wrote:
> You mean "function template" and "class template".
Yes. I meant that.

> yes. It's something along the lines of
>
> template<typename T>
> template<int N>
> void S<T>::foo(int k) {}
>
> template<typename T>
> template<>
> void S<T>::foo<0>(int k) {}

I have tried something as below:

//------------------------------------
#include <iostream>
template<class T> class A {
public:
template<size_t N> void f();
};
template<class T> template<size_t N> void A<T>::f() {
std::cout << N << std::endl;
}
template<class T> template<> void A<T>::f<0>() {
std::cout << "Stopping ..." << std::endl;
}
int main() {
A<int> a;
a.f<10>();
a.f<0>();
}
//------------------------------------

test2.cpp:10: error: invalid explicit specialization before '>' token
test2.cpp:10: error: enclosing class templates are not explicitly
specialized
test2.cpp:10: error: template-id 'f<0>' for 'void A<T>::f()' does not
match any template declaration


Well, as I found there was no matching f<0> to anything, I added
declaration in the class template, so appart from the class definition,
everything looks the same in the code:

//-------------------------------------
#include <iostream>
template<class T> class A {
public:
template<size_t N> void f();
template<> void f<0>();
};
template<class T> template<size_t N> void A<T>::f() {
std::cout << N << std::endl;
}
template<class T> template<> void A<T>::f<0>() {
std::cout << "Stopping ..." << std::endl;
}
int main() {
A<int> a;
a.f<10>();
a.f<0>();
}
//-------------------------------------

but it looks even worse:
test2.cpp:6: error: explicit specialization in non-namespace scope
'class A<T>'
test2.cpp:11: error: invalid explicit specialization before '>' token
test2.cpp:11: error: enclosing class templates are not explicitly
specialized
test2.cpp:11: error: template-id 'f<0>' for 'void A<T>::f()' does not
match any template declaration

So what do you think I am doing wrong here?


Cheers!
Ziko


== 8 of 9 ==
Date: Wed, Apr 1 2009 4:59 am
From: SG


On 1 Apr., 13:23, fabio_canni...@yahoo.com wrote:
> I tried what suggested in SG's mail, but did not work.
> I think specialization of method is not allowed.

I haven't tested member function specialization of a class template
and I thought it was supposed to work. Sorry for the trouble.

As a rule of thumb you should try to avoid specializing function
templates altogether. There are other alternatives (like overloading
function templates or turning a function template into a non-templated
member function of some class template).


Cheers!
SG


== 9 of 9 ==
Date: Wed, Apr 1 2009 5:10 am
From: Triple-DES


On 1 Apr, 12:52, SG <s.gesem...@gmail.com> wrote:
> On 1 Apr., 12:37, ZikO <ze...@op.pl> wrote:
>
>
>
>
>
> > SG wrote:
> > > Yes. Have you tried the namespace scope? :-p
>
> > >   struct S
> > >   {
> > >      template<int N>
> > >      void foo(int k);
> > >   };
>
> > >   template<int N>
> > >   void S::foo(int k) {}
>
> > >   template<>
> > >   void S::foo<0>(int k) {}
>
> > > Cheers!
> > > SG
>
> > Is this also possible for the template function in the template class ?
>
> You mean "function template" and "class template".  The answer is
> yes.  It's something along the lines of
>
>    template<typename T>
>    template<int N>
>    void S<T>::foo(int k) {}
>
>    template<typename T>
>    template<>
>    void S<T>::foo<0>(int k) {}

The second example is ill-formed. A member template can not be
explicitly (fully) specialized unless the enclosing class template is
also explicitly (fully) specialized.

template<>
template<>
void S<int>::foo<0>(int k) {} // ok

template<>
template<int N>
void S<int>::foo<0>(int k) {} // ok

template<typename T>
template<>
void S<T>::foo<0>(int k) {} // ill-formed

==============================================================================
TOPIC: Pruning a std::map efficiently?
http://groups.google.com/group/comp.lang.c++/t/f45ae8609ee5b84c?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Apr 1 2009 1:04 am
From: Jorgen Grahn


Around here, March--April is apple tree pruning time. I have a slighly
different problem:

I have a std::map<K, T> where I want to move all T (or pair<K, T>)
which match some predicate Pred to some other container. The map may
have a size in the millions, and Pred often matches all, or 50%, or
10% or so of the elements.

I'd prefer to use a standard algorithm for this, rather than iterating
manually, dealing with iterator invalidation and so on. Avoiding
repeated tree rebalancing would be welcome, but I suspect it's not
possible.

What's a good std algorithm for this? I guess std::remove_if() doesn't
work on maps -- since you cannot reorder the elements.

Since T is a pointer type in my case, I have some other options. I can
build a new map with only the !Pred elements in it, swap it with the
original, and blow away the original. Not sure that I would gain
performance from that (even more rebalancing?) but at least the code
would be clean ...

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!


== 2 of 2 ==
Date: Wed, Apr 1 2009 3:59 am
From: alasham.said@gmail.com


Hello,

This could be one implementation: copy_if is not part of the standard
library, but is easy to implement (see The C++ Programming Language)

template<typename In, typename Out, typename Pred>
Out copy_if(In first, In last, Out res, Pred Pr)
{
while (first != last)
{
if (Pr(*first))
*res++ = *first;
++first;
}
return res;
}

It is then possible to copy from map m1 to m2, applying predicate
Pred:

copy_if( m1.begin(), m1.end(), std::inserter( m2, m2.begin() ),
Pred );

Regards

==============================================================================
TOPIC: boost::array< pair<>, maxsize >::iterator and adaptor
http://groups.google.com/group/comp.lang.c++/t/2ae60ced74e9c45a?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 1:42 am
From: "Hicham Mouline"


Hello,
I have a boost::array< pair<type1, type2>, maxsize > object, and I wish to
iterate over the list of type1 elements,
and the list of type2 elements...

I gather I then need an iterator adaptor based on array's iterator and
const_iterators...
How can I write such a thing?

rds,

==============================================================================
TOPIC: computer
http://groups.google.com/group/comp.lang.c++/t/fd903a7c5c0d039c?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 3:23 am
From: faizansag@gmail.com


hello

==============================================================================
TOPIC: Inheritance: Implementing pure virtual functions by inheriting from an
object providing an implementation
http://groups.google.com/group/comp.lang.c++/t/93aaba3f11367deb?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 3:31 am
From: Jaco Naude


On Mar 31, 2:30 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Jaco Naude:
>
>
>
> > Hi again,
>
> > I've tried the new implementation but casting becomes really confusing
> > in this implementation.
>
> Casting is generally to be avoided. :)

I actually cast quite a lot between different interfaces on objects. I
work with quite a lot of plugins that implement different interfaces
(IAboutPlugin, IPluginSpecificInterfaces etc.).

>
> > Let me give some details on my implementation.
> > The ManageMe class from my first post looks like this:
>
> > class ManageMe: public GCF::AbstractComponent, public ManagableObject,
> > virtual public IToolbox, virtual public IData
>
> > where each of the parent classes are defined as follows (Using Qt,
> > hence the reason for the QObject class below):
>
> Hm. I only tried installing Qt once, for Windows. Had to try to install three
> times to get it working, and the backspace key didn't work in the installation
> dialog; one wonders how on Earth they managed to make that not work. I was very
> tempted to walk up the street to Trolltech and tell them how uncute their
> product was, and even more tempted when I tried to uninstall...
>
> > class AbstractComponent : public QObject  -- This is a singleton
>
> Double hm. Singletons are generally problematic. When you inherit from a
> singleton class, if that's what you're doing, how do you ensure the singleton
> will be of your class?
>
> > class ManagableObject : virtual public IManagable
> > class IData : virtual public IContainer
> > class IToolbox : virtual public IContainer
> > class IManagable : virtual public IContainer
>
> No AbstractComponent here, AFAICS.

It was defined in the beginning of the list:
class AbstractComponent : public QObject -- This is a singleton


>
> > The IContainer class is a container class defined as follows:
>
> > class IContainer
> > {
> > public:
> >     virtual QObject*        containerObject() = 0;
> > };
>
>  From the name it sames that an IContainer /contains/ a QObject.
>
> > In the ManageMe class the IContainer interface is implemented as
> > follows:
>
> > QObject* ManageMe ::containerObject()
> > {
> >     return this;
> > }
>
> If this compiles then it seems ManageMe inherits from QObject.

Correct, through AbstractComponent

>
> > Ok, that's my class hierarchy explained. Now I'm trying to cast to
> > IManagable* when I have a QObject pointer.
>
> Well, above I see no inheritance relationship between IManagable and QObject. On
> the contrary, IManagable implements the IContainer interface. Which indicates
> that an IManagable is an interface on an object that /contains/ a QObject.
>
>
>
> > The way I try to do it is shown below and causes a program crash:
>
> > if (qobject_ptr) {
> >    ManagableObject* tmp_ref = dynamic_cast<ManagableObject*>
> > (qobject_ptr);
> >    if (tmp_ref) {
> >        IManagable* managable_ptr = dynamic_cast<IManagable*>
> > (tmp_ref);
> >        if (managable_ptr) {
> >             // Access managable_ptr's contents here causes crash.
> >        }
> >    }
> > }
>
> > I've tried various variations of the above without anything working.
> > How is it possible to do this? Is it possible at all?
>
> Try to reproduce the problem in a *minimal* program.
>
> That often helps.
>
> But also think about inheritance versus containment, and think about that
> singleton thing  --  could be a problem.

I agree on this. I am going to use use containment for the
ManagableObject instance.

>
> Also, it seems you have a needless proliferation of interface classes.
>
> Interface abstraction is good when it helps you avoid doing wrong things or
> helps avoid too close coupling, but it's bad when any realistic concrete class
> has to implement and expose umpteen interfaces. Then the abstraction tool that
> should simplify things instead complicates things. That happened a lot with COM;
> if you look up the standard joke "progression of a programmer" starting with
> hello, world in basic, and so on, the final horrifying mess is COM-based code.
>

Thanks for the advice. During my effort to try and solve this I've
read up quite a lot on multiple inheritance and am quite confused in
regard with casting at this stage. However I'll try to make my class
hierarchies simpler to avoid this complexity.

Thanks again for the help.
Regards,
Jaco

> Cheers & hth.,
>
> - Alf
>
> --
> Due to hosting requirements I need visits to <url:http://alfps.izfree.com/>.
> No ads, and there is some C++ stuff! :-) Just going there is good. Linking
> to it is even better! Thanks in advance!


==============================================================================
TOPIC: Eclipse & include file
http://groups.google.com/group/comp.lang.c++/t/03855515fb3c1bbf?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 3:42 am
From: unlexx

Ubuntu 8.10 -- Intrepid
Eclipse 3.4 (Ganymede)

/../
#include <string>
#include <vector>
#include <libpq-fe.h>
/../

Project ->> build ALL
libpq-fe.h: No such file or directory


However
ls -l /usr/include/postgresql/libpq-fe.h
-rw-r--r-- 1 root root 18410 2009-02-11 01:55 /usr/include/postgresql/
libpq-fe.h
Why Eclipse no included file? No work operate directories recursively?
or error in declared include?

==============================================================================
TOPIC: Seeking Enthusiasts of Oil Paintings and Frames Worldwide
http://groups.google.com/group/comp.lang.c++/t/2d8d9e1cdefa2598?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 4:15 am
From: wholesale_ok@126.com


We have various of designs and subjects to be chosen and can make oil
painting from your photos. For more details, please visit our website
or contact us directly .
(we are gold member of Made-in-China)

1) Different sizes and designs are available according to clients'
special requirements.

2) Customers' subjects and own designs are welcome here too.

3) Material: oil paint, mirrior frames and canvas

4) Quality and finishing time guaranteed. All the products will be
inspected carefully before delivery.

5)Package:Roll with tube,standard export package.

6) We assure you the best services at all times.

If you are interested in our products, please contact us for the
further information.

website: www.wholesale789.com

MSN/EMAIL: wholesale789@hotmail.com

==============================================================================
TOPIC: PORTING Applications from 32 bit to 64 bit Architecture
http://groups.google.com/group/comp.lang.c++/t/3fc395032a4427d0?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Apr 1 2009 4:53 am
From: Pallav singh


Hi

are these only the changes we need to do while porting application
from 32 bit architecture to 64 bit architecture ??

In 64 bit architecture, Address is 64 bit but integer is still 32 bit

Architecture Dependencies (64 bit vs 32 bit)
• Data Types and Sizes
• Pointers
Type casts, setting to 0, comparison, pointer arithmetic
• Data Alignment and Padding
Member Alignment, Structure Alignment
• Bit Shifts
Result Type
• Constants
Constant values may have differ(related to size issue)
• Library Calls and Operators
printf, scanf, malloc, calloc, sizeof, memcpy etc

Endianism (Little Endian vs Big Endian)
• Byte Ordering
• Initializing Multiword Entities
• Unused Bytes
Bit masks etc
• Hex Constants Used as Byte Arrays
• Data Transfer Between LE and BE Systems

Other OS Dependencies
• Interprocess Communication (Blocking vs Non Blocking calls)
• Timers
• Signals
Reliable and unreliable
• Communication Stacks, subsystems
• Language Extensions
Ex: Librairies like X11, ACE etc
• Memory mapped files, asynchronous I/O, performance
constraints etc

Tools and Utilities
• Build Environment
Compiler flags, #pragma definitions, default options etc
• Object Formats (Most systems use ELF)

Thanks
Pallav Singh


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: