Thursday, February 26, 2009

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

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

comp.lang.c++@googlegroups.com

Today's topics:

* Pointer typedefs? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/410d4c0b560ec5d5?hl=en
* getting colors from pixels - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/ec161792498b1713?hl=en
* How the standard stl allocator work - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/6345fac0c9bef92b?hl=en
* optimizing function - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/e99c6eb52a9ab0a8?hl=en
* namespace within class - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/dfdcde253ed29b98?hl=en
* cout question - 5 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/8e28a66beef362f7?hl=en
* pop3/imap library - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/926d6e8bccf52d2c?hl=en
* Wonderful!!!!good news!!! Newest NIKE shoes 8-35USD at www.cicigogo.cn
Paypal Payment - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/01df16215a3d8d9f?hl=en
* stl vector performance - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/9e6f2fd1428e62d7?hl=en
* Proper Destruction of Class Members when an Exception is Thrown in
Destructor - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/dd09e78cbbeb28f7?hl=en
* Automatically create a clone() function for derived classes - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/c01181365d327b2f?hl=en
* Alignment - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/0082537bdff8f3d4?hl=en

==============================================================================
TOPIC: Pointer typedefs?
http://groups.google.com/group/comp.lang.c++/t/410d4c0b560ec5d5?hl=en
==============================================================================

== 1 of 3 ==
Date: Wed, Feb 25 2009 10:43 pm
From: zaimoni@zaimoni.com


On Feb 25, 11:14 am, "DaJones" <n...@here.com> wrote:
> Im new to C++, comming over from Delphi, and one thing done in Delphi a lot
> is to define a pointer type like this..
>
> ....
>
> Or in C++
>
> struct Foo .......;
> typedef Foo* PFoo;
>
> I've never actual seen this done in C++ much if at all. And I'm wondering if
> it's just bad style, or wasted effort.. or what?

Once you learn the syntax throughly, this merely incurs an extra level
of indirection for a struct/class/union in C++ (without actually
making it more convenient to compile anything).

The syntax for function pointers (and function references) is not as
easy to casually improvise. My current bias is to use typedefs for
function pointers and function references.

(Unfortunately, I don't know how to construct a function reference
typedef manually. The usual technique for faking a template typedef
does allow defining the function reference typedef.)


== 2 of 3 ==
Date: Thurs, Feb 26 2009 1:54 am
From: pjb@informatimago.com (Pascal J. Bourguignon)


"DaJones" <no@here.com> writes:

> Im new to C++, comming over from Delphi, and one thing done in Delphi a lot
> is to define a pointer type like this..
>
> type
>
> TFoo ..... ;
> PFoo = ^PFoo;
>
> TFoo is a type, and PFoo is a pointer to a TFoo.
>
> Or in C++
>
> struct Foo .......;
> typedef Foo* PFoo;
>
> I've never actual seen this done in C++ much if at all. And I'm wondering if
> it's just bad style, or wasted effort.. or what?
>
> I have to be honest and say I find C++ pointer syntax a bit messy, and
> figured doing this would clean it up a bit, but then it doesnt seem to be
> somthing anyone does, and I'm wondering why.

It's bad style, in C and C++.


You better define your pointer types as you do here:

typedef Foo* PFoo;

and use them, because:

Foo* a,b;

is not the same as:

PFoo a,b;

at all.


That said, I prefer to use a postfix P: FooP or even FooPtr.
In some case, when I define a more abstract API, I would define:

typedef struct { ... } FooS;
typedef FooS* Foo;

and let the users of Foo be oblivious of the fact that it's a pointer.

--
__Pascal Bourguignon__


== 3 of 3 ==
Date: Thurs, Feb 26 2009 10:06 am
From: "Bo Persson"


Pascal J. Bourguignon wrote:
> "DaJones" <no@here.com> writes:
>
>> Im new to C++, comming over from Delphi, and one thing done in
>> Delphi a lot is to define a pointer type like this..
>>
>> type
>>
>> TFoo ..... ;
>> PFoo = ^PFoo;
>>
>> TFoo is a type, and PFoo is a pointer to a TFoo.
>>
>> Or in C++
>>
>> struct Foo .......;
>> typedef Foo* PFoo;
>>
>> I've never actual seen this done in C++ much if at all. And I'm
>> wondering if it's just bad style, or wasted effort.. or what?
>>
>> I have to be honest and say I find C++ pointer syntax a bit messy,
>> and figured doing this would clean it up a bit, but then it doesnt
>> seem to be somthing anyone does, and I'm wondering why.
>
> It's bad style, in C and C++.
>
>
> You better define your pointer types as you do here:
>
> typedef Foo* PFoo;
>
> and use them, because:
>
> Foo* a,b;
>
> is not the same as:
>
> PFoo a,b;
>
> at all.

Ok, so you find an advantage in writing

typedef Foo* PFoo;

PFoo a, b;

while I would just write

Foo* a;
Foo* b;


I have to waste a whole 12 characters in my declarations, while you
use an additional 16 characters in the typedef, so you can get down to
just 8 in the declarations. Let's see now, how much typing did you
save?

(me 12, you 24)


Bo Persson

==============================================================================
TOPIC: getting colors from pixels
http://groups.google.com/group/comp.lang.c++/t/ec161792498b1713?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 26 2009 12:35 am
From: Michael DOUBEZ


BlueJ774 wrote:
> I've tried libgd, which gets the job done, but doesn't play nice with C
> ++ since it's written from a C paradigm. I've tried cimg, but it has
> such crazy overhead. I just want a small portable library or even
> just a header that will allow me to open JPEG and PNG and grab RGB
> data for each individual pixel. Any ideas?

Have you tried Boost.GIL ? It is a header-only part of Boost that allows
importing png and jpg (provided you have libpng and libjpg installed).
The learning curve is a bit harsh but the examples should get you
started quickly for something so simple.

I have used it to generated images from topographic raw data and it
worked like a charm. A very powerful and well abstracted lib IMHO even
if the semantic is verbose and promote template programming rather than
plain use.

--
Michael

==============================================================================
TOPIC: How the standard stl allocator work
http://groups.google.com/group/comp.lang.c++/t/6345fac0c9bef92b?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 26 2009 12:33 am
From: tharinda.gl@gmail.com


Thanks everyone for the comments,

On Feb 26, 10:08 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:

> I don't exactly understand what you are aiming for. The usual way is to
> implement a pooling allocator (or some other custom allocator that
> implements your memory management scheme) and use that allocator for the
> containers.

We knew that creating destroying objects frequently is very in-
efficient. So we have a template based object pooling mechanism in
some processes and when I look into that code it seems that it was
written based on a std::list. So my concern was is it worthless to
write such a pooling mechanism to reduce memory allocations if we are
inserting and removing list elements for every operation (in which it
is indirectly doing the same thing while doing the list operations)?


== 2 of 2 ==
Date: Thurs, Feb 26 2009 3:34 am
From: gob00st@googlemail.com


On Feb 26, 5:00 am, tharinda...@gmail.com wrote:
> Hi,
> Is the standard stl allocator in gcc is bettor (in performance) than
> malloc or is it same as malloc?
>
> I'm going to implement an object pooling mechanism to reduce the
> number of memory allocations and deallocations performed.
>
> It seems pointless to use stl containers (such as std::list) to
> implement such a mechanism if they start doing memory allocations and
> deallocations for every operation I perform on them
>
> TIA,
>
> Tharinda

I think you might need Boost Pool library.

Gob00st

==============================================================================
TOPIC: optimizing function
http://groups.google.com/group/comp.lang.c++/t/e99c6eb52a9ab0a8?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 26 2009 1:21 am
From: puneet vyas


hello, this is the function i wrote for making a series of directory
and subdirectory,is there any optimized way of doing the operation
which i am doing,like using string functions so tht without iterating
over input string path
BOOL DirectoryDetail::CreateSubDirectory(string &dirpath)
{
// File Handle
HANDLE fFile;
// File Information Structure
WIN32_FIND_DATA fileinfo;
// BOOL used to test if Create Directory was successful
BOOL test;
// Counter
int x1 = 0;
// Temporary string Object
string tem = "";
//check Does the file path already exists exist
fFile = FindFirstFile(dirpath.c_str(),&fileinfo);
// if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
//create directory heirarchy
else
{
int length=dirpath.length();
// Parse the supplied string Directory String
for(x1=0;x1<length;x1++)
{
if(dirpath.at(x1) != '\\')
// if the Charachter is not a \
// else add character to temp string
tem += dirpath.at(x1);
else
{
//create directory one level by level
test = CreateDirectory(tem.c_str(),NULL);
if(test)
SetFileAttributes(tem.c_str(),FILE_ATTRIBUTE_NORMAL);
// if the Character is a \ Add the temp string to the vector of string
tem += "\\"; // Now add the \ to the temp string
}
}
// Close the file
FindClose(fFile);
// Now lets see if the directory was successfully created
fFile = FindFirstFile(dirpath.c_str(),&fileinfo);
// if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
else
{
FindClose(fFile);
return FALSE;
}
}
}


== 2 of 2 ==
Date: Thurs, Feb 26 2009 1:42 am
From: SG


On 26 Feb., 09:57, puneet vyas <puneet...@gmail.com> wrote:
> hello, this is the function i wrote for making a series of directory
> and subdirectory,is there any optimized way of doing the operation
> which i am doing,i mean using string functions without iterating over
> string
>
> // recursive directories.cpp : Defines the entry point for the console
> application.
> //
>
> #include "stdafx.h"
> //#include "WriteDir.h"
> #include<stdio.h>
> #include <afx.h>
> #include <CString>
> #include <direct.h>

[snip]

Do you have a concrete question regarding C++ (the language and/or its
standard library)? Most headers you included are Microsoft-specific
and not part of the standard. You might want to ask your question in
another group dedicated to Microsoft extensions/APIs.

Cheers!
SG

==============================================================================
TOPIC: namespace within class
http://groups.google.com/group/comp.lang.c++/t/dfdcde253ed29b98?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 26 2009 3:24 am
From: carlosp


On Feb 25, 4:11 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> carlosp wrote:
> > On Feb 24, 5:25 pm, DerTop...@web.de wrote:
> >> On 24 Feb., 17:06, carlosp <carlospgma...@gmail.com> wrote:
>
> >>> Hello, I am trying to organize a big project. At this point I have a
> >>> class with ~100 methods. I would like to organize them in a similar
> >>> way as with namespaces, but the declaration
> >>> namespace myNamespace { }
> >>> within the class gives an error
> >> That's right, namespaces inside classes are not allowed, and when you
> >> think about, this wouldn't make much sense. What would like to achieve
> >> with namespaces inside classes?
>
> >>> What would be the best way to organize my big class??? (I am still
> >>> sort of rookie in c++)
> >> This depends. Having a class with 100 methods doesn't have to be bad
> >> design (the CWnd class of MS's MFC has about this number of methods).
> >> In general, however, a class with too many methods is a strong
> >> indicator of bad design. In such a case you should try to separate the
> >> class into several classes, each of them with a smaller coherent
> >> interface. If your source code is not confidential, you could post a
> >> small snapshot of the class so that we can help you better.
>
> >> Regards,
> >> Stuart
>
> > Thank you very much. well actually it has a big number of small
> > routines that move sutff and so on. I am not really willing to create
> > new clases, that seems to be to much of an effort.
>
> Is the class concerned with exactly one thing? If not, then you realy
> should consider separating your concerns, possibly moving members into
> new classes which stand-alone, and using composition.
>
> How much effort is it to create new classes, really?  Adding namespaces
> won't actually improve your design, but splitting the class into several
> classes -- each with their own core concern -- likely will improve it
> significantly.
>
> Also, think about this: Code is read and modified a lot more often than
> it is written.  If you don't spend a little extra time/effort to make it
> clean now, you'll spend a lot of time and effort to deal with it later.
>
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Thanks a lot! I will consider your suggestion, though its not clear
for me at this point how to proceed, regarding design. I guess I'll
have to think a bit...

Thanks for your help!

==============================================================================
TOPIC: cout question
http://groups.google.com/group/comp.lang.c++/t/8e28a66beef362f7?hl=en
==============================================================================

== 1 of 5 ==
Date: Thurs, Feb 26 2009 4:18 am
From: chits


Hello Friends ,

Please help me out in this problem..

I need to use scietific notation (1.2e-2 like) for any given number..
i used cout.flags(ios_base::scientific)
now I see the output in 'e' format which is OK...
now I want to capture this output in a string..so basically I want to
capture cout output in a char * buffer ...
How should I do that...

One long way is to write the number in file and then read the file in
a char buffer..

Is their any smarter way for this ?

== 2 of 5 ==
Date: Thurs, Feb 26 2009 4:58 am
From: golgepapaz


use a stringstream;

std::stringstream strm;
double gh = 12354.6786545345436;
strm<< scientific <<gh;
std::cout <<strm.str();


== 3 of 5 ==
Date: Thurs, Feb 26 2009 6:45 am
From: ZikO


chits wrote:
> Hello Friends ,
>
> Please help me out in this problem..
>
> I need to use scietific notation (1.2e-2 like) for any given number..
> i used cout.flags(ios_base::scientific)
Forget about this function it is very tricky as you flags very well
(like setting some flags needs unset the others sometimes). Have a look
at manipulators in <iomanip> library, they very convenient in use.

> now I see the output in 'e' format which is OK...
> now I want to capture this output in a string..so basically I want to
> capture cout output in a char * buffer ...
> How should I do that...
>

The <sstream> defines streams operating on strings not real files.
Essentially, you can put strings, numbers, formatted or unformatted into
such a stream and use/convert it into another form. All works the same
as cout, cin, ofstream, ifstream but you use strings instead of real
files or standard input/output. im gonna provide a part of my file here
so u can familiar with manipulators and stringstreams

// code
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
double tabd[] = {1.23456, 0.000178, 1654.8997, 10};

const size_t roz = sizeof(tabd)/sizeof(double);

cout << "Standard output:" << endl;
for(int i=0; i<roz; ++i) {
cout << "\t" << tabd[i] << endl;
}
cout << endl;

cout << "Scientific notation with lowercase e" << endl;
for(int i=0; i<roz; ++i) {
cout << scientific << setprecision(2) << "\t" << tabd[i] << endl;
}
cout << endl;

cout << "Scientific notation with uppercase E" << endl;
for(int i=0; i<roz; ++i) {
cout << scientific << setprecision(2) << uppercase << "\t" << tabd[i]
<< endl;
}
cout << endl;

ostringstream oss; // string stream from <sstream>
oss << scientific << setprecision(2) << uppercase << tabd[1];
cout << "iss stream contains: " << oss.str() << endl; // str() returns
anything in iss in string form
cout << endl;
return 0;
}


== 4 of 5 ==
Date: Thurs, Feb 26 2009 6:56 am
From: ZikO


First of all, use manipulator instead of flags() function. It's not easy
for someone who does not know flags very well. Manipulators are in
<iomanip> library. Once you've included this you are ready to use them.

The second problem about storing your number in string is not difficult
if you know stringstreams in <sstream> library. stringstreams work
exactly the same as ifstream and ofstream but operate on strings not
files or standard output. They are very handy in many situations.

This is a code which I you can read and familiar with using
stringstreams and manipulators.

#include <iostream>
#include <iomanip>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
double tabd[] = {1.23456, 0.000178, 1654.8997, 10};

const size_t roz = sizeof(tabd)/sizeof(double);

cout << "Standard output:" << endl;
for(int i=0; i<roz; ++i) {
cout << "\t" << tabd[i] << endl;
}
cout << endl;

cout << "Scientific notation with lowercase e" << endl;
for(int i=0; i<roz; ++i) {
cout << scientific << setprecision(2) << "\t" << tabd[i] << endl;
}
cout << endl;

cout << "Scientific notation with uppercase E" << endl;
for(int i=0; i<roz; ++i) {
cout << scientific << setprecision(2) << uppercase << "\t" << tabd[i]
<< endl;
}
cout << endl;

ostringstream oss;
oss << scientific << setprecision(2) << uppercase << tabd[1];
cout << "iss stream contains: " << oss.str() << endl;
cout << endl;
return 0;
}


== 5 of 5 ==
Date: Thurs, Feb 26 2009 7:22 am
From: ZikO


If you want to read about manipulators this is a good reference
http://www.cplusplus.com/reference/iostream/manipulators/

==============================================================================
TOPIC: pop3/imap library
http://groups.google.com/group/comp.lang.c++/t/926d6e8bccf52d2c?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 26 2009 4:23 am
From: nnarayann


On 24 feb, 09:28, Torsten Mueller <dev-n...@shared-files.de> wrote:
> I'm looking for a library. I want to request e-mail accounts from
> within a C++ application. I have the following requirements:
>
> - full pop3 support is needed, imap would be fine
>
> - the lib should be useable on Linux with gcc and on Win32 with either
>   gcc or MSVC
>
> - it should handle coded message text (at least Base64 and quoted
>   printable) and also coded header lines (From and Subject), this
>   means it should have routines to decode these lines correctly
>
> - it should parse the Date header into a binary form
>   (I mean a struct, best would be boost::local_date_time)
>
> - it should be STL/boost compatible
>
> - it must be open source and free for none commercial use
>
> - sending e-mails (SMTP support) is NOT needed
>
> It doesn't matter if it's a C or a C++ library. I could use simple C
> functions as well, but entire C++ classes would be preferred.
>
> Could anyone recommend something useful?
>
> T.M.

Hi!!. I've just started to use (trying actually) Vmime, a C++ library
that supports any POSIX-compatible plattforms like Windows or Linux.
It seems that you can use imap-ssl, pop3s... and it's capable to parse
between quite a few formats.

Keep an eye on: http://www.vmime.org

Hope it helps,

nnarayann.

PS. Keep in touch and sorry for my rusty english :S.

==============================================================================
TOPIC: Wonderful!!!!good news!!! Newest NIKE shoes 8-35USD at www.cicigogo.cn
Paypal Payment
http://groups.google.com/group/comp.lang.c++/t/01df16215a3d8d9f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 26 2009 5:06 am
From: cicitrade601@yahoo.cn


Footwear (paypal payment)(www.cicigogo.cn )
Paul Smith shoes
Jordan shoes
Bape shoes
Chanel shoes (paypal payment)(www.cicigogo.cn )
D&G shoes
Dior shoes
ED hardy shoes
Evisu shoes
Fendi shoes (paypal payment)(www.cicigogo.cn )
Gucci shoes
Hogan shoes (paypal payment)(www.cicigogo.cn )
Lv shoes
Prada shoes (paypal payment)(www.cicigogo.cn )
Timberland shoes
Tous shoes
Ugg shoes (paypal payment)(www.cicigogo.cn )
Ice bream shoes
Sebago shoes (paypal payment)(www.cicigogo.cn )
Lacoste shoes
Air force one shoes (paypal payment)(www.cicigogo.cn )
TODS shoes
AF shoes

Footwear (paypal payment)(www.cicigogo.cn )
Paul Smith shoes
Jordan shoes
Bape shoes
Chanel shoes (paypal payment)(www.cicigogo.cn )
D&G shoes
Dior shoes
ED hardy shoes
Evisu shoes
Fendi shoes (paypal payment)(www.cicigogo.cn )
Gucci shoes
Hogan shoes (paypal payment)(www.cicigogo.cn )
Lv shoes
Prada shoes (paypal payment)(www.cicigogo.cn )
Timberland shoes
Tous shoes
Ugg shoes (paypal payment)(www.cicigogo.cn )
Ice bream shoes
Sebago shoes (paypal payment)(www.cicigogo.cn )
Lacoste shoes
Air force one shoes (paypal payment)(www.cicigogo.cn )
TODS shoes
AF shoes

==============================================================================
TOPIC: stl vector performance
http://groups.google.com/group/comp.lang.c++/t/9e6f2fd1428e62d7?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 26 2009 7:31 am
From: barbaros


On Feb 24, 8:08 am, mojmir <svobod...@gmail.com> wrote:
> in many situations you know the order ahead and therefore you
> can avoid unnecessary allocations. some solution based on
> parametrisation "template <size_t Order>" may perform better.
> depends on our needs, of course.

I do not know how to parametrize the number of (int) arguments of the
constructor or of the operator().

Is it possible ?

Cristian Barbarosie
http://cmaf.ptmat.fc.ul.pt/~barbaros


== 2 of 2 ==
Date: Thurs, Feb 26 2009 9:17 am
From: Victor Bazarov


barbaros wrote:
> On Feb 24, 8:08 am, mojmir <svobod...@gmail.com> wrote:
>> in many situations you know the order ahead and therefore you
>> can avoid unnecessary allocations. some solution based on
>> parametrisation "template <size_t Order>" may perform better.
>> depends on our needs, of course.
>
> I do not know how to parametrize the number of (int) arguments of the
> constructor or of the operator().
>
> Is it possible ?

Not currently, AFAIK.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

==============================================================================
TOPIC: Proper Destruction of Class Members when an Exception is Thrown in
Destructor
http://groups.google.com/group/comp.lang.c++/t/dd09e78cbbeb28f7?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Feb 26 2009 7:47 am
From: "AnonMail2005@gmail.com"


Can someone point me to the specific are of the standard that will
clarify this issue?
I have a class that contains at least one other member. If an
exception is throw in
the destructor, is that member properly destructed?

Sample (non-working) code:

#incude <string>

class Foo
{
public:
// constructor
Foo () {}

// destructor
~Foo ()
{
// do something here that will throw (e.g. some logging)
// is the std::string properly destructed?
}

private:
std::string m_s;
};

thanks


== 2 of 3 ==
Date: Thurs, Feb 26 2009 8:03 am
From: Leandro Melo


On 26 fev, 12:47, "AnonMail2...@gmail.com" <AnonMail2...@gmail.com>
wrote:
> Can someone point me to the specific are of the standard that will
> clarify this issue?
> I have a class that contains at least one other member.  If an
> exception is throw in
> the destructor, is that member properly destructed?
>
> Sample (non-working) code:
>
> #incude <string>
>
> class Foo
> {
> public:
>   // constructor
>   Foo () {}
>
>   // destructor
>   ~Foo ()
>     {
>       // do something here that will throw (e.g. some logging)
>       // is the std::string properly destructed?
>     }
>
> private:
>   std::string m_s;
>
> };

Well, you should start from a very important C++ guideline which says
that destructors should not throw. Never!

If you implement a destructor that might throw you'll be unable to
rely on others well know C++ idioms. Basically, you won't be able to
write exception-safe code and provide any kind of commit-or-rollback
guarantee.

In addition, you'll also be in trouble when using operators like new[]
and delete[].

Bottom line: Don't let your destructors throw.

--
Leandro T. C. Melo


== 3 of 3 ==
Date: Thurs, Feb 26 2009 8:48 am
From: "AnonMail2005@gmail.com"


On Feb 26, 11:03 am, Leandro Melo <ltcm...@gmail.com> wrote:
> On 26 fev, 12:47, "AnonMail2...@gmail.com" <AnonMail2...@gmail.com>
> wrote:
>
>
>
>
>
> > Can someone point me to the specific are of the standard that will
> > clarify this issue?
> > I have a class that contains at least one other member.  If an
> > exception is throw in
> > the destructor, is that member properly destructed?
>
> > Sample (non-working) code:
>
> > #incude <string>
>
> > class Foo
> > {
> > public:
> >   // constructor
> >   Foo () {}
>
> >   // destructor
> >   ~Foo ()
> >     {
> >       // do something here that will throw (e.g. some logging)
> >       // is the std::string properly destructed?
> >     }
>
> > private:
> >   std::string m_s;
>
> > };
>
> Well, you should start from a very important C++ guideline which says
> that destructors should not throw. Never!
>
> If you implement a destructor that might throw you'll be unable to
> rely on others well know C++ idioms. Basically, you won't be able to
> write exception-safe code and provide any kind of commit-or-rollback
> guarantee.
>
> In addition, you'll also be in trouble when using operators like new[]
> and delete[].
>
> Bottom line: Don't let your destructors throw.
>
> --
> Leandro T. C. Melo- Hide quoted text -
>
> - Show quoted text -

Never use the word never!

==============================================================================
TOPIC: Automatically create a clone() function for derived classes
http://groups.google.com/group/comp.lang.c++/t/c01181365d327b2f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 26 2009 9:03 am
From: Noah Roberts


Noah Roberts wrote:

> class Clonable {
> protected:
>
> template < typename T >
> Clonable( T const* t) : pimpl(new impl<T>(t))
> {}
> Clonable * clone() const { return pimpl->clone(); }
>
> private:
> struct impl_base
> {
> virtual Clonable* clone() const = 0;
> };
> template < typename T >
> struct impl : impl_base
> {
> impl(T const* t) : var(t) {}
> Clonable * clone() const { return new T(var); }
> T const* var;
> };
>
> scoped_ptr<impl_base> pimpl;
> };

Actually, thinking about it more I'm pretty confident that this
interface could be further extended so that the clone functionality
isn't even in the class you're using and you could use ANY inheritance
tree in this manner. This would be the optimal design in many cases.

You would simply implement this as a sort of smart pointer that does
deep-cloning on whatever object it points to. Should be relatively
straightforward to implement using the techniques in the above so I'm
not going to do so here.

What would be really nice is a policy based smart pointer that you could
add this functionality to as a policy. Might look into Loki to see if
it's there already.

==============================================================================
TOPIC: Alignment
http://groups.google.com/group/comp.lang.c++/t/0082537bdff8f3d4?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Feb 26 2009 10:00 am
From: "better_cs_now@yahoo.com"


Hello All,

Please consider the two definitions below:

Foo foo;
unsigned char foo[sizeof(Foo)];

Are these guaranteed to have the same alignment, or will the second
definition have an alignment that is only modulo 1?

Thanks,
Dave


== 2 of 3 ==
Date: Thurs, Feb 26 2009 10:05 am
From: Jeff Schwab


better_cs_now@yahoo.com wrote:
> Hello All,
>
> Please consider the two definitions below:
>
> Foo foo;
> unsigned char foo[sizeof(Foo)];
>
> Are these guaranteed to have the same alignment,

No.


== 3 of 3 ==
Date: Thurs, Feb 26 2009 10:18 am
From: Gert-Jan de Vos


On Feb 26, 7:00 pm, "better_cs_...@yahoo.com"
<better_cs_...@yahoo.com> wrote:
> Foo foo;
> unsigned char foo[sizeof(Foo)];
>
> Are these guaranteed to have the same alignment, or will the second
> definition have an alignment that is only modulo 1?

The standard has the answer in 3.1-5 [basic.types]:

"Object types have alignment requirements (3.9.1, 3.9.2). The
alignment of a complete object type is an implementation-defined
integer value representing a number of bytes; an object is allocated
at an address that meets the alignment requirements of its object
type."

So, unless your Foo is a typedef for an array of unsigned char, then
your foo objects are two different types. Therefore both have their
own implementation-defined alignment en you can not portably assume
they will be the same.


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

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: