Fri Apr 26 02:34:23 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2011-05-01

HANGOUT

2024-04-26 | 2024-03-26 | 2024-02-26 | 2024-01-26 | 2023-12-26 | 2023-11-26 | 2023-10-26 | 2023-09-26 | 2023-08-26 | 2023-07-26 | 2023-06-26 | 2023-05-26 | 2023-04-26 | 2023-03-26 | 2023-02-26 | 2023-01-26 | 2022-12-26 | 2022-11-26 | 2022-10-26 | 2022-09-26 | 2022-08-26 | 2022-07-26 | 2022-06-26 | 2022-05-26 | 2022-04-26 | 2022-03-26 | 2022-02-26 | 2022-01-26 | 2021-12-26 | 2021-11-26 | 2021-10-26 | 2021-09-26 | 2021-08-26 | 2021-07-26 | 2021-06-26 | 2021-05-26 | 2021-04-26 | 2021-03-26 | 2021-02-26 | 2021-01-26 | 2020-12-26 | 2020-11-26 | 2020-10-26 | 2020-09-26 | 2020-08-26 | 2020-07-26 | 2020-06-26 | 2020-05-26 | 2020-04-26 | 2020-03-26 | 2020-02-26 | 2020-01-26 | 2019-12-26 | 2019-11-26 | 2019-10-26 | 2019-09-26 | 2019-08-26 | 2019-07-26 | 2019-06-26 | 2019-05-26 | 2019-04-26 | 2019-03-26 | 2019-02-26 | 2019-01-26 | 2018-12-26 | 2018-11-26 | 2018-10-26 | 2018-09-26 | 2018-08-26 | 2018-07-26 | 2018-06-26 | 2018-05-26 | 2018-04-26 | 2018-03-26 | 2018-02-26 | 2018-01-26 | 2017-12-26 | 2017-11-26 | 2017-10-26 | 2017-09-26 | 2017-08-26 | 2017-07-26 | 2017-06-26 | 2017-05-26 | 2017-04-26 | 2017-03-26 | 2017-02-26 | 2017-01-26 | 2016-12-26 | 2016-11-26 | 2016-10-26 | 2016-09-26 | 2016-08-26 | 2016-07-26 | 2016-06-26 | 2016-05-26 | 2016-04-26 | 2016-03-26 | 2016-02-26 | 2016-01-26 | 2015-12-26 | 2015-11-26 | 2015-10-26 | 2015-09-26 | 2015-08-26 | 2015-07-26 | 2015-06-26 | 2015-05-26 | 2015-04-26 | 2015-03-26 | 2015-02-26 | 2015-01-26 | 2014-12-26 | 2014-11-26 | 2014-10-26 | 2014-09-26 | 2014-08-26 | 2014-07-26 | 2014-06-26 | 2014-05-26 | 2014-04-26 | 2014-03-26 | 2014-02-26 | 2014-01-26 | 2013-12-26 | 2013-11-26 | 2013-10-26 | 2013-09-26 | 2013-08-26 | 2013-07-26 | 2013-06-26 | 2013-05-26 | 2013-04-26 | 2013-03-26 | 2013-02-26 | 2013-01-26 | 2012-12-26 | 2012-11-26 | 2012-10-26 | 2012-09-26 | 2012-08-26 | 2012-07-26 | 2012-06-26 | 2012-05-26 | 2012-04-26 | 2012-03-26 | 2012-02-26 | 2012-01-26 | 2011-12-26 | 2011-11-26 | 2011-10-26 | 2011-09-26 | 2011-08-26 | 2011-07-26 | 2011-06-26 | 2011-05-26 | 2011-04-26 | 2011-03-26 | 2011-02-26 | 2011-01-26 | 2010-12-26 | 2010-11-26 | 2010-10-26 | 2010-09-26 | 2010-08-26 | 2010-07-26 | 2010-06-26 | 2010-05-26 | 2010-04-26 | 2010-03-26 | 2010-02-26 | 2010-01-26 | 2009-12-26 | 2009-11-26 | 2009-10-26 | 2009-09-26 | 2009-08-26 | 2009-07-26 | 2009-06-26 | 2009-05-26 | 2009-04-26 | 2009-03-26 | 2009-02-26 | 2009-01-26 | 2008-12-26 | 2008-11-26 | 2008-10-26 | 2008-09-26 | 2008-08-26 | 2008-07-26 | 2008-06-26 | 2008-05-26 | 2008-04-26 | 2008-03-26 | 2008-02-26 | 2008-01-26 | 2007-12-26 | 2007-11-26 | 2007-10-26 | 2007-09-26 | 2007-08-26 | 2007-07-26 | 2007-06-26 | 2007-05-26 | 2007-04-26 | 2007-03-26 | 2007-02-26 | 2007-01-26 | 2006-12-26 | 2006-11-26 | 2006-10-26 | 2006-09-26 | 2006-08-26 | 2006-07-26 | 2006-06-26 | 2006-05-26 | 2006-04-26 | 2006-03-26 | 2006-02-26 | 2006-01-26 | 2005-12-26 | 2005-11-26 | 2005-10-26 | 2005-09-26 | 2005-08-26 | 2005-07-26 | 2005-06-26 | 2005-05-26 | 2005-04-26 | 2005-03-26 | 2005-02-26 | 2005-01-26 | 2004-12-26 | 2004-11-26 | 2004-10-26 | 2004-09-26 | 2004-08-26 | 2004-07-26 | 2004-06-26 | 2004-05-26 | 2004-04-26 | 2004-03-26 | 2004-02-26 | 2004-01-26 | 2003-12-26 | 2003-11-26 | 2003-10-26 | 2003-09-26 | 2003-08-26 | 2003-07-26 | 2003-06-26 | 2003-05-26 | 2003-04-26 | 2003-03-26 | 2003-02-26 | 2003-01-26 | 2002-12-26 | 2002-11-26 | 2002-10-26 | 2002-09-26 | 2002-08-26 | 2002-07-26 | 2002-06-26 | 2002-05-26 | 2002-04-26 | 2002-03-26 | 2002-02-26 | 2002-01-26 | 2001-12-26 | 2001-11-26 | 2001-10-26 | 2001-09-26 | 2001-08-26 | 2001-07-26 | 2001-06-26 | 2001-05-26 | 2001-04-26 | 2001-03-26 | 2001-02-26 | 2001-01-26 | 2000-12-26 | 2000-11-26 | 2000-10-26 | 2000-09-26 | 2000-08-26 | 2000-07-26 | 2000-06-26 | 2000-05-26 | 2000-04-26 | 2000-03-26 | 2000-02-26 | 2000-01-26 | 1999-12-26

Key: Value:

Key: Value:

MESSAGE
DATE 2011-05-24
FROM Ruben Safir
SUBJECT Subject: [NYLXS - HANGOUT] [mrbrklyn@panix.com: (fwd) Template argument determination]
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:34 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!not-for-mail
From: Ruben Safir
Newsgroups: comp.lang.c++
Subject: Template argument determination
Date: Mon, 23 May 2011 20:31:25 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Lines: 120
Message-ID:
NNTP-Posting-Host: www2.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader1.panix.com 1306182685 5873 96.57.23.82 (23 May 2011 20:31:25 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Mon, 23 May 2011 20:31:25 +0000 (UTC)
To: ruben-at-mrbrklyn.com
X-Blackjet: Blackjet is a Yankee Fan
X-DRMisTHEFT: Use GNU Linux today
X-From: A Dark Cloud
X-LOCATION: Brooklyn NY - Forget abou' it!
X-NYLXS: Really - yah think computers are supposed to be broken?
User-Agent: Pan/0.133 (House of Butterflies)
Xref: panix comp.lang.c++:1085207

I'm having trouble understanding why my program is making a change in the
argument type of my template class function

template < class T >
void List::find_value(T val)
{
cursor() = front();
while(cursor() != endd()){
if (*(cursor()->value()) == val)
return;
else{
cursor(cursor()->next());
}
}
if(*(endd()->value()) == val)
return;
else{
cursor() = 0; //park the cursor when nothing is found
}
}


It's part of a List template class

I call it from a templated fucntion in a different namespace as follows:


tally = new chainlist::List >;
tallies = new chainlist::List< chainlist::List< stats::Distribution > *>;

std::cout << "The standard mean for picking 7 is ==> " << stats::mean_list(tallies, 7 ) << std::endl;;

template
float mean_list(chainlist::List< chainlist::List >* > * tallies, T search_val){
if(tallies->endd() == 0){
std::cout << "Empty List" << std::endl;
return 0.0;
}
int sum = 0;
chainlist::List > * dump;
tallies->cursor() = tallies->front();
while(tallies->cursor() != tallies->endd() ){
//tallies->cursor()->value()->find_value(search_val);
dump = *(tallies->cursor()->value());
//dump->cursor() = dump->endd();
//std::cout << "Testing\n" << *(dump->cursor()->value()) << std::endl;
dump->find_value(search_val);
if(dump->cursor() != NULL)
sum += dump->cursor()->value()->population();
tallies->cursor(tallies->cursor()->next());
}
dump = *(tallies->cursor()->value());
dump->find_value(search_val);
if(dump->cursor() != 0)
sum += dump->cursor()->value()->population();
float tot = (float) sum/(float)(tallies->size());
std::cout << "Mean " << tot << " sum " << sum << " size " << tallies->size() << std::endl;
return tot;

}

Now T is an integer for mean_list, and the first argument is of type

chainlist::List< chainlist::List >* > * when called and the second argument is of type int

I then pass int search_val to method chainlist::List::find_value(T) where T = stats::Distribution (where T is an int)
on this line:

dump->find_value(search_val);

and that's where the weirdness happens. I have a type mismatch since I'm sending by value an integer instead of a stats::Distribution

Instead the program calls the stat::Distribution constructor using 7, the value of search_val, as an argument redrawing search_val as type
to a Distribution

:in gdb


312 void List::find_value(T val)
313 {
314 cursor() = front();
315 while(cursor() != endd()){
316 if (*(cursor()->value()) == val)
317 return;
318 else{
319 cursor(cursor()->next());
320 }
321 }
322 if(*(endd()->value()) == val)
323 return;
324 else{
325 cursor() = 0; //park the cursor when nothing is found
326 }
327 }

chainlist::List >::find_value (this=0x804f008, val=...) at linklist.h:314
(gdb) ptype val
type = class stats::Distribution {
public:
chainlist::List > *tally;
private:
int freq;
int occurances;

public:
void Distribution(int, int);
void Distribution(void);
int description(void) const;
int population(void) const;
void increase_occ(void);
void descrease_occ(void);
int operator()(void);
bool operator==(stats::Distribution &);
bool operator<(stats::Distribution &);
float stddev(chainlist::List > *);
}


What rule for Template argument matching allows for this kind of magic?

-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:35 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!bloom-beacon.mit.edu!micro-heart-of-gold.mit.edu!nntp.club.cc.cmu.edu!feeder.erje.net!news.ett.com.ua!not-for-mail
From: "Balog Pal"
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 13:06:13 +0200
Organization: ETT newsserver
Lines: 19
Message-ID:
References:
NNTP-Posting-Host: bc240436.catv.pool.telekom.hu
Mime-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="UTF-8";
reply-type=original
Content-Transfer-Encoding: 7bit
X-Complaints-To: usenet-at-news.ett.com.ua
X-Notice: Filtered by postfilter v. 0.6.1
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
Xref: panix comp.lang.c++:1085242

"Ruben Safir"
> i knew nobody would have an insight on this :(

Are you sure you want insight actually expressed?

Well, to put it straight, the code you post here would better fit
thedailywtf. Most of it is as far from healthy C++ as you can get. FUBAR.

It is not clear where you got it, if it is part of some homework, please
regroup, read some fundamental books on how to approach C++ ( Effective C++
and coupe of similar books, then The C++ Coding Standards), and start over
from scratch.

If it is from some production, well, figure out what I would suggest...

This group is fine to help where one is stuck on some particular problem or
need guidance. But who would write a book-ful of text for someone did not
bother with the FAQ and the material printed long ago?

-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:35 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!not-for-mail
From: Ruben Safir
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 15:04:29 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Lines: 34
Message-ID:
References:


NNTP-Posting-Host: www2.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader1.panix.com 1306249469 3672 96.57.23.82 (24 May 2011 15:04:29 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Tue, 24 May 2011 15:04:29 +0000 (UTC)
X-Blackjet: Blackjet is a Yankee Fan
X-DRMisTHEFT: Use GNU Linux today
X-From: A Dark Cloud
X-LOCATION: Brooklyn NY - Forget abou' it!
X-NYLXS: Really - yah think computers are supposed to be broken?
User-Agent: Pan/0.133 (House of Butterflies)
Xref: panix comp.lang.c++:1085259

Lets look at it this way

why does this fail to compile

template
void test_me(stats::Distribution hello){
std::cout << "I recied an int and converted it to an object " << hello << std::endl;
}



int main ( int argc, char *argv[] ){
int a = 7;
test_me(a);

return EXIT_SUCCESS;
}


yet this does, with the promotion of the int to a distribution object


template
void test_me(stats::Distribution hello){
std::cout << "I received an int and converted it to an object " << hello << std::endl;
}


int main ( int argc, char *argv[] ){
int a = 7;
test_me(a);

return EXIT_SUCCESS;
}
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:35 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!not-for-mail
From: Ruben Safir
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 14:44:20 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Lines: 11
Message-ID:
References:

NNTP-Posting-Host: www2.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader1.panix.com 1306248260 804 96.57.23.82 (24 May 2011 14:44:20 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Tue, 24 May 2011 14:44:20 +0000 (UTC)
X-Blackjet: Blackjet is a Yankee Fan
X-DRMisTHEFT: Use GNU Linux today
X-From: A Dark Cloud
X-LOCATION: Brooklyn NY - Forget abou' it!
X-NYLXS: Really - yah think computers are supposed to be broken?
User-Agent: Pan/0.133 (House of Butterflies)
Xref: panix comp.lang.c++:1085258

On Tue, 24 May 2011 13:06:13 +0200, Balog Pal wrote:


> This group is fine to help where one is stuck on some particular problem
> or need guidance. But who would write a book-ful of text for someone did
> not bother with the FAQ and the material printed long ago?
>

Thanks for the follow up. It's neither homework or production. It's
just a test program to shake out some Template libraries constructed as
an exercise,
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:35 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!news.linkpendium.com!news.linkpendium.com!feeder.erje.net!news.ett.com.ua!not-for-mail
From: "Balog Pal"
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 17:33:46 +0200
Organization: ETT newsserver
Lines: 17
Message-ID:
References:
NNTP-Posting-Host: bc240436.catv.pool.telekom.hu
Mime-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="UTF-8";
reply-type=original
Content-Transfer-Encoding: 7bit
X-Complaints-To: usenet-at-news.ett.com.ua
X-Notice: Filtered by postfilter v. 0.6.1
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
Xref: panix comp.lang.c++:1085261

"Ruben Safir"
> why does this fail to compile
>
> template
> void test_me(stats::Distribution hello);
>
> int main ( int argc, char *argv[] ){
> int a = 7;
> test_me(a);
>
> yet this does, with the promotion of the int to a distribution object
> test_me(a);

IIRC it is called "non-deduced context".
How do you think the compiler could figure the T you meant for a general
case?

-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: Victor Bazarov
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 11:43:26 -0400
Organization: A noiseless patient Spider
Lines: 49
Message-ID:
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 24 May 2011 15:43:27 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="mfoyPVXLF0MtM1ZkAsRgyQ";
logging-data="31217"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX1/C7I8P09Pb9rAZBZkqJC1eaXCrnxP8Yw0="
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To:
Cancel-Lock: sha1:xwmh1LRs4qzK91MZjldtaTdR8fE=
Xref: panix comp.lang.c++:1085263

On 5/24/2011 11:04 AM, Ruben Safir wrote:
> Lets look at it this way
>
> why does this fail to compile
>
> template
> void test_me(stats::Distribution hello){
> std::cout<< "I recied an int and converted it to an object "<< hello<< std::endl;
> }
>
>
>
> int main ( int argc, char *argv[] ){
> int a = 7;
> test_me(a);
>
> return EXIT_SUCCESS;
> }

You ask the compiler to find what 'T' would be. During template
argument deduction the compiler does NOT use any potential promotions or
conversions. The fact that 'stats::Distribution' has a conversion
from 'int' has *no importance* to the template argument deduction process.

>
>
> yet this does, with the promotion of the int to a distribution object
>
>
> template
> void test_me(stats::Distribution hello){
> std::cout<< "I received an int and converted it to an object "<< hello<< std::endl;
> }
>
>
> int main ( int argc, char *argv[] ){
> int a = 7;
> test_me(a);

Here no template argument deduction is necessary since you supplied the
argument.

>
> return EXIT_SUCCESS;
> }

V
--
I do not respond to top-posted replies, please don't ask
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.cloud9consultinginc!news.posted.cloud9consultinginc.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 24 May 2011 12:32:59 -0500
Newsgroups: comp.lang.c++
From: "A. Bolmarcich"
Subject: Re: Template argument determination
References:
Message-ID:
User-Agent: slrn/0.9.8.0 (FreeBSD)
Date: Tue, 24 May 2011 12:32:59 -0500
Lines: 65
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 168.100.1.1
X-Trace: sv3-wm4TXZbaEE7LDSQjB/jnI46v5+Y88RIU9vvafOO8Q/4qQxh346Zqeqf0ZGMV9n6B0DJv76glGnRpyP9!KxF6cSQ+ufKaUuDlocLtwRF0QdkqditdwxeUpgCZZAj7h3ADKhBoALPjKyza1kvB0LitbAedbNlP!njik9/fY4dMn79kTkKw=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2911
Xref: panix comp.lang.c++:1085272

> I'm having trouble understanding why my program is making a change in the
> argument type of my template class function

A short answer is that what you are seeing is due to an implicit
conversion that is part of the C++ programming language. If you do
not want this implicit conversion done, declare the constructor
being used by the implicit conversion as explcit, as it

class Distribution {
public:
explicit Distribution(int i) {
// whatever the constructor does
}
}

What follows are details, with most of the source you gave snipped
down to essentials.

> template < class T >
> void List::find_value(T val)
> {
[snip]
> }

[snip]

> tallies = new chainlist::List< chainlist::List< stats::Distribution > *>;
>
> std::cout << "The standard mean for picking 7 is ==> " << stats::mean_list(tallies, 7 ) << std::endl;;
>
> template
> float mean_list(chainlist::List< chainlist::List >* > * tallies, T search_val){
[snip]
> chainlist::List > * dump;

> dump->find_value(search_val);
[snip]
> }

[snip]

The expression

stats::mean_list(tallies, 7 )

implicitly instantiates the mean_list function template. Due to the
argument types, the instantiated function includes the declaration

chainlist::List > * dump;

The expression

dump->find_value(search_val)

implicitly instantiates the find_value member function template.
Due to the type of the object for which the member function is
called, the instantiated member function is

void List >::find_value(
stats::Distribution val)

In the call to that function by dump->find_value(search_val), an
implicit conversion by constructor is done to convert the search_val
argument (of type int) to a stats::Distribution (the type of
the parameter).
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.cloud9consultinginc!news.posted.cloud9consultinginc.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 24 May 2011 14:32:36 -0500
Newsgroups: comp.lang.c++
From: "A. Bolmarcich"
Subject: Re: Template argument determination
References:
Message-ID:
User-Agent: slrn/0.9.8.0 (FreeBSD)
Date: Tue, 24 May 2011 14:32:36 -0500
Lines: 12
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 168.100.1.1
X-Trace: sv3-Z7PE49lWjbeCuX5NbJyxa4tS68nK/eJ6fPlButpFYFvcxcz1qo7SUYat40NfmNE5ZRhgxe2z5tATnJZ!TECdSV6GZpylrJ4jiyt8n2WJjYB3KwSSytAup13cgQVLxsgaZbumZXWymM9oo9e4K486oK/lelZL!6AjBx8EsWc7FqihCx9U=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1518
Xref: panix comp.lang.c++:1085279

On 2011-05-24, Ruben Safir wrote:

> Bingo - thanks for taking the time to give me this explanation. But its not
> capable of doing this implicit conversation unless T is defined as an int.
> The compiler couldn't deduce this otherwise.

A compiler should do the implicit conversion as long as the parameter type has
an accessible

- non-explicit constructor that can take a value of type T as the only
argument, or
- conversion function of the form: operator T()
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!not-for-mail
From: Ruben Safir
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 18:08:32 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Lines: 80
Message-ID:
References:

NNTP-Posting-Host: www2.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader1.panix.com 1306260512 11831 96.57.23.82 (24 May 2011 18:08:32 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Tue, 24 May 2011 18:08:32 +0000 (UTC)
X-Blackjet: Blackjet is a Yankee Fan
X-DRMisTHEFT: Use GNU Linux today
X-From: A Dark Cloud
X-LOCATION: Brooklyn NY - Forget abou' it!
X-NYLXS: Really - yah think computers are supposed to be broken?
User-Agent: Pan/0.133 (House of Butterflies)
Xref: panix comp.lang.c++:1085273

On Tue, 24 May 2011 12:32:59 -0500, A. Bolmarcich wrote:

>> I'm having trouble understanding why my program is making a change in
>> the argument type of my template class function
>
> A short answer is that what you are seeing is due to an implicit
> conversion that is part of the C++ programming language. If you do not
> want this implicit conversion done, declare the constructor being used
> by the implicit conversion as explcit, as it
>
> class Distribution {
> public:
> explicit Distribution(int i) {
> // whatever the constructor does
> }
> }
>
> What follows are details, with most of the source you gave snipped down
> to essentials.
>
>> template < class T >
>> void List::find_value(T val)
>> {
> [snip]
>> }
>
> [snip]
>
>> tallies = new chainlist::List< chainlist::List<
>> stats::Distribution > *>;
>>
>> std::cout << "The standard mean for picking 7 is ==> " <<
>> stats::mean_list(tallies, 7 ) << std::endl;;
>>
>> template
>> float mean_list(chainlist::List<
>> chainlist::List >* > * tallies, T
>> search_val){
> [snip]
>> chainlist::List > * dump;
>
>> dump->find_value(search_val);
> [snip]
>> }
>
> [snip]
>
> The expression
>
> stats::mean_list(tallies, 7 )
>
> implicitly instantiates the mean_list function template. Due to the
> argument types, the instantiated function includes the declaration
>
> chainlist::List > * dump;
>
> The expression
>
> dump->find_value(search_val)
>
> implicitly instantiates the find_value member function template. Due to
> the type of the object for which the member function is called, the
> instantiated member function is
>
> void List >::find_value(
> stats::Distribution val)
>
> In the call to that function by dump->find_value(search_val), an
> implicit conversion by constructor is done to convert the search_val
> argument (of type int) to a stats::Distribution (the type of the
> parameter).



Bingo - thanks for taking the time to give me this explanation. But its not
capable of doing this implicit conversation unless T is defined as an int.
The compiler couldn't deduce this otherwise.


Ruben
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!news1.as3257.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: Victor Bazarov
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 15:48:22 -0400
Organization: A noiseless patient Spider
Lines: 36
Message-ID:
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 24 May 2011 19:48:23 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="mfoyPVXLF0MtM1ZkAsRgyQ";
logging-data="8638"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX1+2tFtFA0g1sjXcec1a8gmFkX/hNeZsqww="
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To:
Cancel-Lock: sha1:qVibubQXx7jaWmPFnrx+WKo0UzI=
Xref: panix comp.lang.c++:1085281

On 5/24/2011 3:32 PM, A. Bolmarcich wrote:
> On 2011-05-24, Ruben Safir wrote:
>
>> Bingo - thanks for taking the time to give me this explanation. But its not
>> capable of doing this implicit conversation unless T is defined as an int.
>> The compiler couldn't deduce this otherwise.
>
> A compiler should do the implicit conversion as long as the parameter type has
> an accessible
>
> - non-explicit constructor that can take a value of type T as the only
> argument, or
> - conversion function of the form: operator T()

OK, try compiling this:

template struct FromT {
FromT(T) {} // here is your non-explicit c-tor
};

template void foo(FromT ft) {}

int main() {
foo(42);
}

And then explain. Then change the line in 'main' to

foo(42);

and try again. And if the results are different, try to explain why
they are.

V
--
I do not respond to top-posted replies, please don't ask
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:36 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.cloud9consultinginc!news.posted.cloud9consultinginc.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 24 May 2011 17:11:50 -0500
Newsgroups: comp.lang.c++
From: "A. Bolmarcich"
Subject: Re: Template argument determination
References:
Message-ID:
User-Agent: slrn/0.9.8.0 (FreeBSD)
Date: Tue, 24 May 2011 17:11:50 -0500
Lines: 29
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 168.100.1.1
X-Trace: sv3-uc8maIm5mAkaEyPgNj4ssSj9Y8/uTA61pCY8BIimUTrhasJZoZJfJzP6/s9+MUuZyxh+KUa94i4OUSA!seXRH9vm4Hjr/ljL/tyPvh2Fpna3cfdDMybeAgJTjAJo4r0DD26mkMIgcgfzklG47EjHXEdPDr1P!0riKg0OUlkI9zul7UTk=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1931
Xref: panix comp.lang.c++:1085293

On 2011-05-24, Victor Bazarov wrote:
> OK, try compiling this:
>
> template struct FromT {
> FromT(T) {} // here is your non-explicit c-tor
> };
>
> template void foo(FromT ft) {}
>
> int main() {
> foo(42);
> }
>
> And then explain. Then change the line in 'main' to
>
> foo(42);
>
> and try again. And if the results are different, try to explain why
> they are.

For original program with foo(42), the template for foo is not instantiated
because the compiler is not able to deduce the template argument to use for
T.

With foo(4), the template argument to use for T is explicitly specified.
The instantiated function is void foo(FromT ft). In the call to that
function, the argument value 42 is implicitly converted using the FromT(int)
constructor (of the struct FromT that was implicitly instantiated due
to it being the type of the parameter of foo).
-- end of forwarded message --

----- End forwarded message -----
----- Forwarded message from Ruben Safir -----

Date: Tue, 24 May 2011 19:27:37 -0400 (EDT)
From: Ruben Safir
To: ruben-at-mrbrklyn.com
Subject: (fwd) Re: Template argument determination
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386))

-- forwarded message --
Path: reader1.panix.com!panix!bloom-beacon.mit.edu!micro-heart-of-gold.mit.edu!nntp.club.cc.cmu.edu!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: Victor Bazarov
Newsgroups: comp.lang.c++
Subject: Re: Template argument determination
Date: Tue, 24 May 2011 19:04:02 -0400
Organization: A noiseless patient Spider
Lines: 52
Message-ID:
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=KOI8-R; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 24 May 2011 23:04:07 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="J3EW1I9Cuyi1wJAW+L/yWA";
logging-data="23872"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX18xo8DWCPxWlva6SvzbpaZ8dNuTESDFEFY="
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To:
Cancel-Lock: sha1:DNU53VNbONVT6ZmOPUA66iatXsU=
Xref: panix comp.lang.c++:1085296

On 5/24/2011 6:11 PM, A. Bolmarcich wrote:
> On 2011-05-24, Victor Bazarov wrote:
>> OK, try compiling this:
>>
>> template struct FromT {
>> FromT(T) {} // here is your non-explicit c-tor
>> };
>>
>> template void foo(FromT ft) {}
>>
>> int main() {
>> foo(42);
>> }
>>
>> And then explain. Then change the line in 'main' to
>>
>> foo(42);
>>
>> and try again. And if the results are different, try to explain why
>> they are.
>
> For original program with foo(42), the template for foo is not instantiated
> because the compiler is not able to deduce the template argument to use for
> T.

Perhaps I didn't understand your statement. I seems you said that the
compiler was supposed to use the conversion as basis for deducing the
template argument from the function call with 42. You snipped this:

> On 2011-05-24, Ruben Safir wrote:
>
>> > Bingo - thanks for taking the time to give me this explanation. But its not
>> > capable of doing this implicit conversation unless T is defined as an int.
>> > The compiler couldn't deduce this otherwise.
> A compiler should do the implicit conversion as long as the parameter type has
> an accessible
>
> - non-explicit constructor that can take a value of type T as the only
> argument, or
> - conversion function of the form: operator T()

Let me explain what I am reading here. Ruben: "compiler cannot use any
conversion unless T is defined". You: "A compiler should do the
conversion." - as if it doesn't matter whether type is deduced or not.

> [..]

Anyway, probably doesn't matter at this point.

V
--
I do not respond to top-posted replies, please don't ask
-- end of forwarded message --

----- End forwarded message -----

  1. 2011-05-02 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  2. 2011-05-06 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] NYLXS Business
  3. 2011-05-06 Ron Guerin <ron-at-vnetworx.net> Re: [NYLXS - HANGOUT] NYLXS Business
  4. 2011-05-06 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Business
  5. 2011-05-09 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] UPDATED! NYLUG Presents: 5/18 -at- 6:30PM Cameron L. Fadjo on Construct, Program, Design: An Introduction to Scratch From the Perspective of Computing and Cognition
  6. 2011-05-09 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Notes
  7. 2011-05-10 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Workshop / Hacking Society (Smalltalk, C++, Python) Tuesday May 10 6:00PM-8:00PM
  8. 2011-05-15 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Notes
  9. 2011-05-16 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Notes
  10. 2011-05-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: [New-York-C-Developers-Group] MongoNYC - MongoDB Conference
  11. 2011-05-16 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  12. 2011-05-18 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [rick-at-linuxmafia.com: [conspire] YouTube downloading software
  13. 2011-05-19 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - creating a distribution list
  14. 2011-05-19 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - creating a distribution list
  15. 2011-05-20 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  16. 2011-05-22 Ron Guerin <ron-at-vnetworx.net> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  17. 2011-05-22 Ron Guerin <ron-at-vnetworx.net> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  18. 2011-05-23 swd <sderrick-at-optonline.net> Subject: [NYLXS - HANGOUT] Membership Dues Address?
  19. 2011-05-23 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Membership Dues Address?
  20. 2011-05-23 swd <sderrick-at-optonline.net> RE: [NYLXS - HANGOUT] Membership Dues Address?
  21. 2011-05-23 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Template Argument type deterination
  22. 2011-05-23 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Membership Dues Address?
  23. 2011-05-23 swd <sderrick-at-optonline.net> RE: [NYLXS - HANGOUT] Membership Dues Address?
  24. 2011-05-23 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Membership Dues Address?
  25. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [ian.bruntlett-at-gmail.com: [accu-general] Free e-book:- The
  26. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Job Fair
  27. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [billy.donahue-at-gmail.com: Re: [mrbrklyn-at-panix.com: Template
  28. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re: [mrbrklyn-at-panix.com: Template Argument
  29. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re: [mrbrklyn-at-panix.com: Template Argument
  30. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re:
  31. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re:
  32. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re:
  33. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] template implicit converstion
  34. 2011-05-24 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Workshop / Hacking Society (Smalltalk, C++, Python) Tuesday May 24 6:00PM-8:00PM
  35. 2011-05-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [mrbrklyn-at-panix.com: (fwd) Template argument determination]
  36. 2011-05-25 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  37. 2011-05-25 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS -
  38. 2011-05-26 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Presents: 6/15 -at- 6:30PM Robert Menes on Rockbox: Open Source Jukebox Firmware
  39. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [ruben-at-mrbrklyn.com: Re: [NYLXS - HANGOUT] C++ Workshop - New
  40. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [ruben-at-mrbrklyn.com: Re: [NYLXS - HANGOUT] C++ Workshop - New
  41. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [ruben-at-mrbrklyn.com: Re: [NYLXS - HANGOUT] C++ Workshop - New
  42. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Perl Class
  43. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Perl Class
  44. 2011-05-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Postgres Class
  45. 2011-05-26 Paul Robert Marino <prmarino1-at-gmail.com> Re: [NYLXS - HANGOUT] Postgres Class
  46. 2011-05-27 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop - next phase
  47. 2011-05-27 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Consensus from last night's meeting
  48. 2011-05-27 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Re: [The-New-York-Perl-Meetup-Group] Consensus from last night's
  49. 2011-05-30 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Job opennings
  50. 2011-05-31 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!