Question about boost::function menu

User Tag List

Results 1 to 3 of 3
  1. #1
    GliderPro's Avatar Member
    Reputation
    -1
    Join Date
    Mar 2009
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about boost::function

    I'm messing around with boost function and I came up with the following code. This isn't much different than using a typedef to declare a function pointer so I'm probably doing something wrong. boost::function is supposed to make things cleaner, right?

    Will someone show me the proper way to use boost::function?

    Code:
    boost::function< int (const char *) > impPyRun_SimpleString;
    boost::function< int () > impPy_Initialize;
    boost::function< int () > impPy_IsInitialized;
    boost::function< PyGILState_STATE () > impPyGILState_Ensure;
    boost::function< void (PyGILState_STATE) > impPyGILState_Release;
    
    void InitFunctionPointers()
    {
      impPyRun_SimpleString = (int (*)(const char *))GetProcAddress(GetModuleHandleA("python25"), "PyRun_SimpleString");
      impPy_Initialize = GetProcAddress(GetModuleHandleA("python25"), "Py_Initialize");
      impPy_IsInitialized = GetProcAddress(GetModuleHandleA("python25"), "Py_IsInitialized");
      impPyGILState_Ensure = (PyGILState_STATE (*)())GetProcAddress(GetModuleHandleA("python25"), "PyGILState_Ensure");
      impPyGILState_Release = (void (*)(PyGILState_STATE))GetProcAddress(GetModuleHandleA("python25"), "PyGILState_Release");
    }

    Question about boost::function
  2. #2
    pendra's Avatar Active Member
    Reputation
    46
    Join Date
    Jul 2008
    Posts
    42
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The purpose of boost::function is to abstract a function pointer from a specific, precise function signature to any function signature for which conversion operators have been defined. It is only interesting when you want to specify function pointers that will point at different functions during their lifetimes, and you want to allow for type conversions and such in the functions they point at.

    So for example, if you have a function pointer void (*)(FizzWidget &a) , then it can only point at a function that takes a FizzWidget reference and returns void. With a boost::function object, on the other hand, you can point it at a function which takes any object that can be converted to a FizzWidget, so it's more flexible.

    This flexibility is useful if you're say, writing a sort function that takes a comparator function pointer as an argument and you don't want the user of your sort function to have to nitpick about whether the comparator funciton they provide takes references or pointers or shared ptrs or whatever.

    In your case where the function pointers always point at the same thing, it doesn't really help. I would just use a typedef.

  3. #3
    GliderPro's Avatar Member
    Reputation
    -1
    Join Date
    Mar 2009
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. That clears things up.

Similar Threads

  1. Question about the search function
    By MouseMD in forum World of Warcraft General
    Replies: 0
    Last Post: 03-21-2013, 06:20 AM
  2. question about model editing
    By Zanatons in forum WoW ME Questions and Requests
    Replies: 1
    Last Post: 08-17-2006, 09:21 PM
  3. questions about model editing
    By Zanatons in forum WoW ME Questions and Requests
    Replies: 1
    Last Post: 08-17-2006, 05:32 PM
  4. Question about MCing - Frostwolf
    By Hydrox in forum World of Warcraft General
    Replies: 0
    Last Post: 07-21-2006, 02:53 AM
  5. questions about model editing
    By Avianar47 in forum World of Warcraft General
    Replies: 2
    Last Post: 07-08-2006, 09:41 PM
All times are GMT -5. The time now is 03:37 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search