Saturday, February 15, 2014

Can't think of a good subject

Newsgroup: comp.lang.c++

Subject: Can't think of a good subject

From: woodbrian77@...

Date: Wed, 12 Feb 2014 19:45:10 -0800 (PST)





I'm not sure why the behavior of the following

two functions differs here. The only difference

in these functions is in the body of the loop.



template <class R>

void Receive (::cmw::ReceiveBuffer<R>& buf

,empty_container<cmw::File>& az1)

{

int32_t count[1];

count[0]=buf.template Give<uint32_t>();

for(;count[0]>0;--count[0]){

cmw::File inst(buf); // named

}

}





template <class R>

void Receive (::cmw::ReceiveBuffer<R>& buf

,empty_container<cmw::File>& az1)

{

int32_t count[1];

count[0]=buf.template Give<uint32_t>();

for(;count[0]>0;--count[0]){

cmw::File (buf);

}

}





The first (named) version works the way I want

it to, and the second version, built with either

gcc or clang doesn't. Both compilers are

producing smaller text segments for the second

version. And the results for that version

(both compilers) are like nothing is being done

in the loop.



Can someone explain this? In another file I

have some code similar to the second version

and it works fine:



while(fgets(lineBuf,300,Fl.FlHndl)){

token=strtok(lineBuf," ");

if(strcmp("Header",token)) break;

cmw::File (strtok(nullptr,"\n ")).Marshal(buf);

}



I've simplified that loop a little, but don't

think I've removed anything important. There

are different constructors being used in these

two cases.



http://ift.tt/1kJmjpJ



Thanks.



Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1gDONNy

View all the progranning help forums at:

http://ift.tt/1dP9txN

Friday, February 14, 2014

a totally self balanced tree for unsigned integers...

Newsgroup: comp.lang.c++

Subject: a totally self balanced tree for unsigned integers...

From: "Chris M. Thomasson" <no@...>

Date: Fri, 14 Feb 2014 13:44:40 -0800



I do not even want to go into why James tried to post this as his own!



:^/ GRRRR!!!!! #$%#$% FUC32432KL#$@...





Anyway, He made a fatal mistake! My name is in my cryptic MACROS!!!!



Take a look:



http://ift.tt/1eYaCcl





HAW HAW!!!!!





:^)





Anyway, I need to use it now for a database.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1eYaEB1

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, February 9, 2014

Return by reference

Newsgroup: comp.lang.c++

Subject: Return by reference

From: Giuliano Bertoletti <gbe32241@...>

Date: Sun, 09 Feb 2014 12:50:38 +0100





Hello,



I've a classes like this:



class SubObject { ... };



class Object {

public:

SubObject sub;

};



class MyClass {

public:

Object obj;



public:

SubObject &GetSubObject() { return obj.sub; } // shortcut

};



which is the difference of calling?



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

MyClass c;



SubObject &sub = c.GetSubObject();

SubObject sub = c.GetSubObject();

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



It compiles both ways.



In practice I've an higher number of nested classes, so GetSubObject()

is actually a shortcut which digs deep into MyClass and retrieves the

item I need.



Giulio.























via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1fWFLLL

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, February 6, 2014

show all subset of a set

Newsgroup: comp.lang.c++

Subject: show all subset of a set

From: mary8shtr@...

Date: Thu, 6 Feb 2014 08:13:54 -0800 (PST)



A program is a set of all subsets of this part of the show. Users can enter a number., For example, if n = 2 the output looks like this:

{}

{1}

{2}

{1,2}

or for n=3 we have:

{}

{1}

{2}

{3}

{1,2}

{1,3}

{2,3}

{1,2,3}

meantime this program should be solved with tow way.

recursive function and Non-recursive.Can also be used in solving the problem of bitwise operations.



my algorithm that is for per subset exists one number. these numbers are form 0 until (2^n)-1.allow me explain it with a example.

n=3

{ } 000 0

{1} 100 4

{2} 010 2

{3} 001 1

{1,2} 110 6

{1,3} 101 5

{2,3} 011 3

{1,2,3} 111 7

The third column show some number(fn) that i use in code.now we know per number of subset has to state(sn).0 or 1. this means it exists or not exists.now i should match fn and sn.and suggested way is use of bitwise operators.(operator &).and now i don't know what do and thing with else thing.

#include <iostream>

using namespace std;

#include <conio.h>

#include <string.h>

int pow(int a,int b)

{

int p=1;

for(int i=0;i<b;i++)

p=p*a;

return p;

}

struct ar

{

int binary;

int content;

};

int main()



{

int testcase=0;

int n;

ar *a;

a=new ar [2000];

cin>>testcase;

int i=0;

while(i<testcase)

{

cin>>n;

for(int j=0,k=1;j<n;j++,k++)

{

a[j].content=k;

a[j].binary=2;

}





for(int p=0;p<pow(2,n)-1;p++)

{

cout<<'{';

for(int m=0;m<n;m++)

{



int b;

b=a[m].binary&p;

if(b==1)

cout<<a[i].content<<' ';



}

cout<<'}';

}



cout<<endl;

i++;

}

return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/LVdQRq

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wednesday, February 5, 2014

question regarding the shared_ptr use_count

Newsgroup: comp.lang.c++

Subject: question regarding the shared_ptr use_count

From: somenath <somenathpal@...>

Date: Sun, 2 Feb 2014 17:12:57 -0800 (PST)



I am not able to understand the behavior of the following program



#include <iostream>

#include<memory>

#include<string>

using namespace std;



int main() {

auto p1 = make_shared<string> (10,'S');

cout<<"p1 use_count = "<<p1.use_count()<<endl;

shared_ptr<string> p2(new string()) ;

p1 = p2;

cout<<"p2 use_count = "<<p2.use_count()<<endl;

cout<<"second p1 use_count = "<<p1.use_count()<<endl;

return 0;

}

Output

++++++++++++++++

p1 use_count = 1

p2 use_count = 2

second p1 use_count = 2



I can understand the first two print. At beginning p1 points to one string so the reference count is 1.

When the statement p1=p2; executes p2's reference count gets incremented to 2 but at the same time I was expecting that p1's reference count to be decremented by 1 as p1 would be pointing to p2 now.

Please let me know where my understanding is going wrong?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1keZz0q

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, February 1, 2014

Address one past the end of array - is this syntax a valid C++?

Newsgroup: comp.lang.c++

Subject: Address one past the end of array - is this syntax a valid C++?

From: Peter <pilarp@...>

Date: Sat, 1 Feb 2014 09:23:39 -0800 (PST)



Assume we have an array:



int arr[5];



It's legal to refer to address arr + 5, but, of course, illegal to refer to element arr[5] as it's not part of the array. However, arr + n is equivalent to &arr[n]. My question is: does this equivalence also hold for an edge case of

n = 5 (or, generally, n equal to number of elements of array)?



While there's nothing wrong with arr + 5, &arr[5] looks highly suspicious: it looks like in the first step arr[5] is evaluated (which introduces an undefined behaviour) which would mean the expression as a whole is undefined. Does the equivalence still hold in this special case?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1i4Tpfr

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, January 30, 2014

i really need help

Newsgroup: comp.lang.c++

Subject: i really need help

From: mary8shtr@...

Date: Thu, 30 Jan 2014 07:34:04 -0800 (PST)



Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cB0tAa

View all the progranning help forums at:

http://ift.tt/1dP9txN