Thread: Branching vs array indexing

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by smokeyangel
    Didn't sound crazy until I looked up the command pattern -- looks, err, rather heavyweight!
    wildcard_seven's particular suggestion is basically the same idea as mapping indices to function pointers in an array, except that the table has keys that are not necessarily just numbers, and they map to function objects rather than function pointers.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Quote Originally Posted by laserlight View Post
    wildcard_seven's particular suggestion is basically the same idea as mapping indices to function pointers in an array, except that the table has keys that are not necessarily just numbers, and they map to function objects rather than function pointers.
    Oh... ok. That sounds more reasonable. I was looking at Command pattern - Wikipedia, the free encyclopedia as wildcard_seven mentioned "command pattern" and it's what he said, but with a load more decoupling.

    I can see the advantages in looking up functions with a Key rather than an index. I'm afraid I don't see the advantage of function objects over function pointers. [edit] but I see a google search has a few results on this matter.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Function objects allow the compiler to inline functions bwcause the compiler can see the functions. With pointers, it cannot do this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Function objects allow the compiler to inline functions bwcause the compiler can see the functions.
    That's true, but in this case the suggestion involved putting instances of a function object with abstract interfaces into a table so the compiler wouldn't be able to see the functions.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. probability branching
    By Dale in forum C# Programming
    Replies: 5
    Last Post: 11-18-2011, 10:32 AM
  2. Minimizing array lookup times using effective indexing...?
    By The Dog in forum Game Programming
    Replies: 5
    Last Post: 02-08-2011, 07:11 AM
  3. Array Indexing w/ strlen()
    By c++_n00b in forum C++ Programming
    Replies: 8
    Last Post: 06-04-2002, 11:18 AM
  4. Branching?
    By Brian in forum C Programming
    Replies: 1
    Last Post: 01-20-2002, 11:06 AM
  5. array indexing
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-01-2001, 11:42 AM