Sun Nov 24 23:11:05 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 2015-09-01

LEARN

2024-11-24 | 2024-10-24 | 2024-09-24 | 2024-08-24 | 2024-07-24 | 2024-06-24 | 2024-05-24 | 2024-04-24 | 2024-03-24 | 2024-02-24 | 2024-01-24 | 2023-12-24 | 2023-11-24 | 2023-10-24 | 2023-09-24 | 2023-08-24 | 2023-07-24 | 2023-06-24 | 2023-05-24 | 2023-04-24 | 2023-03-24 | 2023-02-24 | 2023-01-24 | 2022-12-24 | 2022-11-24 | 2022-10-24 | 2022-09-24 | 2022-08-24 | 2022-07-24 | 2022-06-24 | 2022-05-24 | 2022-04-24 | 2022-03-24 | 2022-02-24 | 2022-01-24 | 2021-12-24 | 2021-11-24 | 2021-10-24 | 2021-09-24 | 2021-08-24 | 2021-07-24 | 2021-06-24 | 2021-05-24 | 2021-04-24 | 2021-03-24 | 2021-02-24 | 2021-01-24 | 2020-12-24 | 2020-11-24 | 2020-10-24 | 2020-09-24 | 2020-08-24 | 2020-07-24 | 2020-06-24 | 2020-05-24 | 2020-04-24 | 2020-03-24 | 2020-02-24 | 2020-01-24 | 2019-12-24 | 2019-11-24 | 2019-10-24 | 2019-09-24 | 2019-08-24 | 2019-07-24 | 2019-06-24 | 2019-05-24 | 2019-04-24 | 2019-03-24 | 2019-02-24 | 2019-01-24 | 2018-12-24 | 2018-11-24 | 2018-10-24 | 2018-09-24 | 2018-08-24 | 2018-07-24 | 2018-06-24 | 2018-05-24 | 2018-04-24 | 2018-03-24 | 2018-02-24 | 2018-01-24 | 2017-12-24 | 2017-11-24 | 2017-10-24 | 2017-09-24 | 2017-08-24 | 2017-07-24 | 2017-06-24 | 2017-05-24 | 2017-04-24 | 2017-03-24 | 2017-02-24 | 2017-01-24 | 2016-12-24 | 2016-11-24 | 2016-10-24 | 2016-09-24 | 2016-08-24 | 2016-07-24 | 2016-06-24 | 2016-05-24 | 2016-04-24 | 2016-03-24 | 2016-02-24 | 2016-01-24 | 2015-12-24 | 2015-11-24 | 2015-10-24 | 2015-09-24 | 2015-08-24 | 2015-07-24 | 2015-06-24 | 2015-05-24 | 2015-04-24 | 2015-03-24 | 2015-02-24 | 2015-01-24 | 2014-12-24 | 2014-11-24 | 2014-10-24

Key: Value:

Key: Value:

MESSAGE
DATE 2015-09-07
FROM Ruben Safir
SUBJECT Subject: [LIU Comp Sci] C++ Fwd: Re: References to const
From owner-learn-outgoing-at-mrbrklyn.com Mon Sep 7 13:48:51 2015
Return-Path:
X-Original-To: archive-at-mrbrklyn.com
Delivered-To: archive-at-mrbrklyn.com
Received: by mrbrklyn.com (Postfix)
id D44C716117A; Mon, 7 Sep 2015 13:48:51 -0400 (EDT)
Delivered-To: learn-outgoing-at-mrbrklyn.com
Received: by mrbrklyn.com (Postfix, from userid 28)
id C778B16117F; Mon, 7 Sep 2015 13:48:51 -0400 (EDT)
Delivered-To: learn-at-nylxs.com
Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89])
by mrbrklyn.com (Postfix) with ESMTP id 1C61216117A
for ; Mon, 7 Sep 2015 13:48:27 -0400 (EDT)
Received: from [10.0.0.19] (www.mrbrklyn.com [96.57.23.82])
by mailbackend.panix.com (Postfix) with ESMTPSA id 6008317481
for ; Mon, 7 Sep 2015 13:48:27 -0400 (EDT)
Message-ID: <55EDCDEB.6000601-at-panix.com>
Date: Mon, 07 Sep 2015 13:48:27 -0400
From: Ruben Safir
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version: 1.0
To: learn-at-nylxs.com
Subject: [LIU Comp Sci] C++ Fwd: Re: References to const
References:
In-Reply-To:
X-Forwarded-Message-Id:
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Sender: owner-learn-at-mrbrklyn.com
Precedence: bulk
Reply-To: learn-at-mrbrklyn.com




-------- Forwarded Message --------
Subject: Re: References to const
Date: Wed, 29 Jul 2015 20:41:48 CST
From: Richard
Reply-To: Richard
Organization: multi-cellular, biological
Newsgroups: comp.lang.c++.moderated
References:


[Please do not mail me a copy of your followup]

Robert spake the secret code
thusly:

>C++ Primer page 61 "..we can initialize a reference to const from any
>expression that can be converted to the type of the reference. In
>particular, we can bind a reference to const to a nonconst object, a
>literal, or a more general expression."
>
>What is the reason for this exception?

It means that you can have a function or method that accepts a parameter by
const reference and call that function or method with an instance of a
non-const object.

This is really the only way that it makes sense to use const references;
otherwise the only thing you could associate with a const reference would be
a const object and most objects change at *some* point in the program.

Consider the following function:

bool ends_with_foo(const std::string &text) {
return text.size() >= 3U && text.substr(text.size()-3) == "foo"; }

This function is saying that it's parameter 'text' is obtained by a const
reference to std::string. The const means we promise not to modify the
argument inside the function -- which is good because this function is
acting like a predicate and it shouldn't be changing the object under
inspection.

If we could only call 'ends_with_foo' on const strings, this would be
unfortunate, because we'd end up doing needless copies just to be able to
call this predicate. The rule that allows a const reference to be
initialized from a non-const object makes the predicate useful in the
obvious way:

std::string ender{"I end with foo"};
std::string unender{"I end with bar"};
bool yes = ends_with_foo(ender);
bool no = ends_with_foo(unender);

Otherwise I'd have to get things into a constant string just to be able to
query it:

std::string ender{"I end with foo"};
const std::string const_ender{ender};
std::string unender{"I end with bar"};
const std::string const_unender{unender}; bool yes =
ends_with_foo(const_ender); bool no = ends_with_foo(const_unender);

--
"The Direct3D Graphics Pipeline" free book
The Computer Graphics Museum
The Terminals Wiki
Legalize Adulthood! (my blog)


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]



  1. 2015-09-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: Panel about technology in higher education.
  2. 2015-09-07 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] C++ Fwd: Re: References to const
  3. 2015-09-07 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Re: [isoc-ny] WEBCAST TODAY: Armenian Internet Governance Forum
  4. 2015-09-09 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Artifical Intell
  5. 2015-09-09 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [csconnection-at-computer.org: VIEW NOW: The Total Economic Impact of
  6. 2015-09-10 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Artificial Intelligence and CLIPS
  7. 2015-09-10 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: Wednesday: Join us at "Freedom in my Heart"
  8. 2015-09-10 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Internt of things...
  9. 2015-09-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: Re: When to use threaded interrupts?
  10. 2015-09-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] IEEE Aritifical Intelligence
  11. 2015-09-18 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] AI lectures
  12. 2015-09-18 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: Re: "Know Your Language: C Rules Everything Around Me (Part
  13. 2015-09-18 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: Re: fork() on a machine without paging hardware
  14. 2015-09-23 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Writing Kernel Driver tutorial
  15. 2015-09-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Artificial Intelligence in Perl

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