C++ Templates book discussion

This is a discussion on C++ Templates book discussion within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by manutd Agreed. Good debate, but this isn't going to get resolved anytime soon. Each person can have ...

  1. #31
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by manutd
    Agreed. Good debate, but this isn't going to get resolved anytime soon. Each person can have their own opinion(s), so lets leave it there.
    but you havent given the typelist example yet

  2. #32
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You just want a most basic one?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #33
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by manutd
    You just want a most basic one?
    at least an infinite number of types should be possible

  4. #34
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Yes, but you need to be more specific. Here's one, holding all floating points:
    Code:
    template <class H, class T>
    struct typelist
    {
        typedef H head;
        typedef T tail;
    };
     
    class null_typelist {};
    
    typedef typelist<float, typelist<double, typelist<long double, null_typelist> > > fpt;
    Of course there are other ways to do this, but this is one.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #35
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    C++ Templates: The Complete Guide was loaned to me by my boss and... well, when the boss gives you a book you read it. =) I'm still only about halfway done with it though, so

    I enjoy reading this book. It comes off a bit like a book of trivia however. Somethings in it (like eclectic uses of the typename keyword) I can imagine using, but in the years I've coded, it hasn't come up. Other features (the use of export w/ respect to templates) will pretty obviously never be in itself, useful information.

    So, is the book useless? Yes and no. The book is not meant as a functional education of templates. Also, it's not really better than just reading the standard as a reference. The book is mainly of interest because it discusses obscure template features.

    These obscure features are part of the language for the sake of addressing fundamental problems with templates. Reading about these makes you consider the nature of the beast. If you were, say, going to write a language which uses templates, then this would be a very good read because it gives you a perspective of the wisdom and flaws of C++'s templates.
    Callou collei we'll code the way
    Of prime numbers and pings!

  6. #36
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by manutd
    Yes, but you need to be more specific. Here's one, holding all floating points:
    lol indeed I should've been more specific. The article you copy pasted that from is a lot longer though with the get functions and all, but even in this small example you're using lots of template features which need explaining.
    a template struct with just 2 typedefs of its template parameters. An empty class as list terminater needs explaining, the recursive template instantiation etc. And the example in the article is just a prerequisite to making VARIANT type unions possible with which you can mix classes and primitive types in a union which is normally not possible.
    Also, in modern C++ design he makes way more typelists possible.
    And this is just 1 thing you can do with metaprogramming, theres much much more.
    Definately can use a few books to have all the information packed in one with a good explanation.

  7. #37
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    No kidding. I gave one example. I didn't explain, it wasn't a tutorial. And, yes, I copied and pasted, to prove my point that this information is available online.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #38
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by manutd
    No kidding. I gave one example. I didn't explain, it wasn't a tutorial. And, yes, I copied and pasted, to prove my point that this information is available online.
    No in the article the features and why he does that etc arent explained either! If you only use the internet to learn templates, then the article only gets useful if you found the other bits of information about metaprogramming at a random site somewhere else.

    but whatever, this thread bores me ^^

  9. #39
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    I also found a pdf first with no code examples but explanation..I skipped it because I already know how to do this.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a chain-structure
    By MalickT in forum C Programming
    Replies: 12
    Last Post: 03-27-2008, 05:51 AM
  2. Looking for a c++ book, didn't were to post this...
    By Rune Hunter in forum C++ Programming
    Replies: 6
    Last Post: 09-24-2004, 06:32 PM
  3. Replies: 5
    Last Post: 09-19-2004, 06:52 AM
  4. Must read book!
    By RealityFusion in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-15-2004, 09:05 PM
  5. Should i get a new reference book?
    By Raison in forum Windows Programming
    Replies: 2
    Last Post: 06-15-2004, 10:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21