From: Frederick Gotham on
Greg Herlihy:

> A const reference is no misnomer:
>
> int i;
> const int& iRef = i;


What you have there is a "reference to const" -- a reference cannot be
declared as const.


> iRef is clearly a "const reference" - and not a "reference to const"
> because the object iRef refers to, i, is not const.


int i;

const int* p = &i;

Is "p" not a "pointer to const" because i is non-const? Please.


> The const attribute in this example is purely an invention of - and
> applies only to - the iRef reference variable - thereby making iRef a
> const reference.

The following denotes something which is a "X to const":

int const *p
int const &i

The following denotes something which is const:

int *const p
int &const i /* Opps! */

--

Frederick Gotham

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

From: Greg Herlihy on

Gabriel Dos Reis wrote:
> "Greg Herlihy" <greghe(a)pacbell.net> writes:
>
> [...]
>
> | A const reference is no misnomer:
> |
> | int i;
> | const int& iRef = i;
> |
> | iRef is clearly a "const reference" - and not a "reference to const"
> | because the object iRef refers to, i, is not const.
>
> There is nothing such as "object iRef", because a reference is not an
> object.

Agreed. Nor does my sentence refer an "object iRef" because there is an
implicit "which" that separates "object" from "iRef", like so:

iRef is clearly a "const reference" - and not a "reference to const"
because the object which iRef refers to - i - is not const.

Greg


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

From: Seungbeom Kim on
Gabriel Dos Reis wrote:
> "Greg Herlihy" <greghe(a)pacbell.net> writes:
>
> [...]
>
> | A const reference is no misnomer:
> |
> | int i;
> | const int& iRef = i;
> |
> | iRef is clearly a "const reference" - and not a "reference to const"
> | because the object iRef refers to, i, is not const.
>
> There is nothing such as "object iRef", because a reference is not an
> object.

That statement doesn't parse in the way you thought. :)

the object [iRef refers to] is not const

is the correct interpretation, I believe.

--
Seungbeom Kim

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

From: James Kanze on
Gennaro Prota wrote:
> On 29 Oct 2006 11:03:40 -0500, James Kanze wrote:

> >[...]
> >> FWIW, and to keep your anti-obfuscation radar fit ;-), my SHA-1
> >> implementation has the following:

> >> const sha1_loop /* loop */ ( state, block );

> >> Opinions/suggestions/insults? (I know that I could just use a
> >> static function, but I'm not convinced that that is an
> >> improvement)

> >If you want to call a function, call a function. I'm not sure
> >what this buys you -- you get two successive function calls in
> >one statement (construtor and destructor), but I don't see any
> >real advantage in this.

> Putting everything into a class (sha1_loop) was the first thing that
> came to my mind.

Every what? If there was something to put into a class, I would
agree, but I don't see anything.

> I'm far from sure it is the best arrangement of the
> code. The goal anyway was to facilitate loop unrolling for the
> compiler; the sha_1_loop constructor looks (more or less) like this:

> sha1_loop( word_type( &state )[ 5 ],
> const word_type( &block )[ 16 ] )
> : a( state[0] ), b( state[1] ), c( state[2] ),
> d( state[3] ), e( state[4] )
> {
> std::copy( ... );

> for( int i = 16; i < 80; ++i )
> {
> w[ i ] = rotate_left< 1 >( w[i-3] ^ w[i-8]
> ^ w[i-14] ^ w[i-f] );
> }

> // main computation
> loop_core< 0 >();

> state[ 0 ] += a;
> state[ 1 ] += b;
> state[ 2 ] += c;
> state[ 3 ] += d;
> state[ 4 ] += e;
> }

> where the loop_core member is declared as

> template< int i >
> void loop_core();

> and specialized to a no-op for i = 80.

And with some fancy meta-template logic for the other cases, no
doubt, looping up from 0.

And your profiler really showed that you needed this, given
everything that is going on in each loop? (But I'm not sure I
understand what is going on here. My code loops only 4 times,
not 80. And I don't mind looping, because each loop in turn
loops over the entire block.)

> The reason why using a class was the first thing that came to
> mind is that I needed to keep a, b, c, d and e.

Beyond the end of the function? (Certainly you know that you
can define variables in a function in C++.)

--
James Kanze (GABI Software) email:james.kanze(a)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


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

From: James Kanze on
Gennaro Prota wrote:
> On 28 Oct 2006 21:33:35 -0400, Frederick Gotham wrote:

> >James Kanze:

> >> It's probably regrettable, but the usage is
> >> too well established to change.

> >I'm not afraid to go against the grain when it comes to
> >well-established wrongs.

> I'm absolutely with you.

Which isn't likely to change anything, either.

> Analogously for "class template"/"template
> class" and "function template"/"template function". Another couple of
> couples of expressions often used without care.

Yes. Two distinct expressions... for three distinct meanings:
the template itself, its specialization, and the instantiation
of the specialization.

--
James Kanze (GABI Software) email:james.kanze(a)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


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