Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.raspberry-pi > #11021

Translate C++: 5-lines

From noSpam@gmail.com
Newsgroups comp.sys.raspberry-pi, comp.os.linux.misc
Subject Translate C++: 5-lines
Date 2016-03-07 17:21 +0000
Organization A noiseless patient Spider
Message-ID <nbkdb0$oav$1@dont-email.me> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


I don't want to learn C++, but this writer has some interesting ideas
which I want to be able to understand:
http://matt.might.net/articles/c++-template-meta-programming-with-l
ambda-calculus/

He writes:-- start extract --------------
   The canonical example of compile-time computation is factorial in
   templates:
template <int N> <-following code is called a template. Where's the endToken?
struct Factorial <-following code in "{}" is a structure/RECORD
{
  enum { value = N * Factorial<N-1>::value };
};

template <>
struct Factorial<0>  <- yes we know: fact(0) == 1
{
  enum { value = 1 } ; <- but explain the syntax!
};

   Without the template specialization, a reference to
   Factorial<4>::value would re-write itself forever, eventually
   causing the template equivalent of a stack overflow.

   Note the use of enumerations to force compile-time evaluation of the
   member constant value.

   With this template in place, code could refer to Factorial<4>::value
   and get 24 computed at compile-time.
------------------------------ end of extract --------
I 'come from' PASCAL..Oberon, rather than from C.
The "<- arrows" are my guess at the C++ meanings.
What means:  enum   -- in detail?
Why use "< >" ?
Does: "::" <token>      mean token is the functions return value?

== TIA

Back to comp.sys.raspberry-pi | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Translate C++: 5-lines noSpam@gmail.com - 2016-03-07 17:21 +0000
  Re: Translate C++: 5-lines Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-03-07 20:04 +0200
    Re: Translate C++: 5-lines mm0fmf <none@invalid.com> - 2016-03-07 18:10 +0000
    Re: Translate C++: 5-lines noSpam@gmail.com - 2016-03-08 19:48 +0000
      Re: Translate C++: 5-lines Chick Tower <c.tower@deadspam.com> - 2016-03-09 18:11 +0000

csiph-web