[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Casting from const pair* to const pair*

Alex Vinokur

10/12/2008 11:16:00 AM

Hi,

Is it possible to do C++-casting from
const pair<const unsigned char*, size_t>*
to
const pair<unsigned char*, size_t>*
?

Alex Vinokur
13 Answers

CHICANERY

5/18/2008 5:53:00 PM

0


"Patriot Games" <Patriot@America.Com> wrote in message
news:vcl0345rdobc8rsu0dpuclsa6j1qo0s17f@4ax.com...
> On Sun, 18 May 2008 09:23:56 -0400, "Harry Dope"
> <Pres.McCain08@earthlink.com> wrote:
>> Day 2
>
> Is he dead yet!?!?!?!
>
> Rumor has it that his seizures were a sight to see!!
>
> All 386 pounds flapping around on the floor, foaming at the mouth,
> massive bowel and bladder emptying!!!
>
> "Aarrugh! <flapflipflop...> AARugh! Ugh! <Pootpootpoot, squirt>
> ArrUGH! Nancy! ArrUGH! <flapflipflop...>

Hastert the Hut? Fag, drunk, unbathed?


BR549

5/19/2008 12:22:00 AM

0

On May 18, 12:35 pm, Deaf Power <d...@power.com> wrote:
> On Sun, 18 May 2008 12:17:28 -0400, Patriot Games
>
> <Patr...@America.Com> wrote:
> >On Sun, 18 May 2008 09:23:56 -0400, "Harry Dope"
> ><Pres.McCai...@earthlink.com> wrote:
> >>   Day 2
>
> >Is he dead yet!?!?!?!
>
> Ahhh, the sign of blood lusting neocon killers.
>
>
>
> >Rumor has it that his seizures were a sight to see!!
>
> >All 386 pounds flapping around on the floor, foaming at the mouth,
> >massive bowel and bladder emptying!!!
>
> >"Aarrugh!  <flapflipflop...> AARugh!  Ugh! <Pootpootpoot, squirt>
> >ArrUGH! Nancy! ArrUGH! <flapflipflop...>- Hide quoted text -
>
> - Show quoted text -

FUCKING RIGHT !!! I've been praying that fuckers untimely demise for
40 years. Even an evil liberal kook like Jabba Kennedy can't live
forever. I would'nt be surprised if after the douchebag cacks Piglosi
will prop him up in a corner with a broomstick up his ass so his
senate seat won't be lost. He's so pickled he'll never rot.

Patriot Games

5/19/2008 3:01:00 PM

0

On Sun, 18 May 2008 10:53:12 -0700, "CHICANERY" <BushBlows@home.net>
wrote:
>"Patriot Games" <Patriot@America.Com> wrote in message
>news:vcl0345rdobc8rsu0dpuclsa6j1qo0s17f@4ax.com...
>> On Sun, 18 May 2008 09:23:56 -0400, "Harry Dope"
>> <Pres.McCain08@earthlink.com> wrote:
>>> Day 2
>> Is he dead yet!?!?!?!
>> Rumor has it that his seizures were a sight to see!!
>> All 386 pounds flapping around on the floor, foaming at the mouth,
>> massive bowel and bladder emptying!!!
>> "Aarrugh! <flapflipflop...> AARugh! Ugh! <Pootpootpoot, squirt>
>> ArrUGH! Nancy! ArrUGH! <flapflipflop...>
>Hastert the Hut?

He didn't have a seizure.

> Fag, drunk, unbathed?

Teddy. He had two flapping seizures.

Erik Wikström

10/12/2008 12:18:00 PM

0

On 2008-10-12 13:16, Alex Vinokur wrote:
> Hi,
>
> Is it possible to do C++-casting from
> const pair<const unsigned char*, size_t>*
> to
> const pair<unsigned char*, size_t>*
> ?

const_cast might work, but I don't think this counts as casting away
constness, you should probably use reinterpret_cast.

--
Erik Wikström

Barry

10/12/2008 12:23:00 PM

0

On Oct 12, 7:16 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
> Hi,
>
> Is it possible to do C++-casting from
> const pair<const unsigned char*, size_t>*
> to
> const pair<unsigned char*, size_t>*
> ?
>

const pair<const unsigned char*, size_t>* p1 = 0;
const pair<unsigned char*, size_t>* p2 =
reinterpret_cast<const pair<unsigned char*, size_t>*>(p1);

but reinterpre_cast should be avoided if possible.
*Practically*, I wonder you can just do it this way:

char* s = const_cast<char*>(p1->first);

Or can you tell me the scenario you are in?

--
Best Regards
Barry

Alex Vinokur

10/12/2008 1:05:00 PM

0

On Oct 12, 2:22 pm, Barry <dhb2...@gmail.com> wrote:
> On Oct 12, 7:16 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
>
> > Hi,
>
> > Is it possible to do C++-casting from
> > const pair<const unsigned char*, size_t>*
> > to
> > const pair<unsigned char*, size_t>*
> > ?
>
>   const pair<const unsigned char*, size_t>* p1 = 0;
>   const pair<unsigned char*, size_t>* p2 =
>         reinterpret_cast<const pair<unsigned char*, size_t>*>(p1);
>
> but reinterpre_cast should be avoided if possible.
> *Practically*, I wonder you can just do it this way:
>
>   char* s = const_cast<char*>(p1->first);
>
> Or can you tell me the scenario you are in?
>

I have function foo1 (const pair<unsigned char*, size_t>* p);
I need also function foo2 (const pair<const unsigned char*, size_t>*
p) that does the same thing as foo1().

Currently
void foo2 (const pair<const unsigned char*, size_t>* p)
{
// I would like to use here C++-style casting
const pair<unsigned char*, size_t>* p1 = ( const pair<unsigned
char*, size_t>* ) p;
foo1(p1);
}

Alex Vinokur

Sam

10/12/2008 1:09:00 PM

0

Alex Vinokur writes:

> Hi,
>
> Is it possible to do C++-casting from
> const pair<const unsigned char*, size_t>*
> to
> const pair<unsigned char*, size_t>*
> ?

Yes, if you write your own conversion function. Although, if you are
attempting to do something like this, then it's fairly likely that whatever
you're really trying to do, you're doing it the wrong way.


Barry

10/12/2008 1:46:00 PM

0

On Oct 12, 9:05 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
> On Oct 12, 2:22 pm, Barry <dhb2...@gmail.com> wrote:
>
>
>
> > On Oct 12, 7:16 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
>
> > > Hi,
>
> > > Is it possible to do C++-casting from
> > > const pair<const unsigned char*, size_t>*
> > > to
> > > const pair<unsigned char*, size_t>*
> > > ?
>
> >   const pair<const unsigned char*, size_t>* p1 = 0;
> >   const pair<unsigned char*, size_t>* p2 =
> >         reinterpret_cast<const pair<unsigned char*, size_t>*>(p1);
>
> > but reinterpre_cast should be avoided if possible.
> > *Practically*, I wonder you can just do it this way:
>
> >   char* s = const_cast<char*>(p1->first);
>
> > Or can you tell me the scenario you are in?
>
> I have function foo1 (const pair<unsigned char*, size_t>* p);
> I need also function foo2 (const pair<const unsigned char*, size_t>*
> p) that does the same thing as foo1().
>
> Currently
> void foo2 (const pair<const unsigned char*, size_t>* p)
> {
>   // I would like to use here C++-style casting
>   const pair<unsigned char*, size_t>* p1 = ( const pair<unsigned
> char*, size_t>* ) p;
>   foo1(p1);
>
> }
>

I'm sorry that my previous post misled you.
I think sam got my answer.

What I asked is that I was confused that why you need
such conversion. And I was expecting to see if there's some
way to avoid such conversion.

If you just wanted to learn the language. OK, "reinterpret_cast"
as C++-style cast, or just use C-style cast. While in practice,
avoid doing this.

--
Best Regards
Barry

peter koch

10/12/2008 2:08:00 PM

0

On 12 Okt., 13:16, Alex Vinokur <ale...@users.sourceforge.net> wrote:
> Hi,
>
> Is it possible to do C++-casting from
> const pair<const unsigned char*, size_t>*
> to
> const pair<unsigned char*, size_t>*
> ?
>
> Alex Vinokur

Only a reinterpret_cast works: the two types are unrelated. Why do you
want to do this? It would be better to fix your design instead.

/Peter

James Kanze

10/13/2008 9:28:00 AM

0

On Oct 12, 4:08 pm, peter koch <peter.koch.lar...@gmail.com> wrote:
> On 12 Okt., 13:16, Alex Vinokur <ale...@users.sourceforge.net> wrote:
> > Is it possible to do C++-casting from
> > const pair<const unsigned char*, size_t>*
> > to
> > const pair<unsigned char*, size_t>*
> > ?

> Only a reinterpret_cast works: the two types are unrelated.
> Why do you want to do this? It would be better to fix your
> design instead.

Reinterpret_cast doesn't work. You can't do a reinterpret_cast
to or from a user defined type, and instantiations of std::pair
are considered user defined types.

What he can do is construct a new std::pair, e.g.:

std::pair< unsigned char*, size_t > const p2
= std::make_pair(
const_cast< unsigned char* >( p1.first ),
p2.second ) ;

--
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