Thread: #define "functions"

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    #define "functions"

    Code:
    bool is_type2(const boost::any & operand, const type_info & dtype)
    {	//comparison of types using a typeinfo
    	if (operand.type() == dtype)
    		return true;
    	return false;
    }
    
    #define is_type(a,b) is_type2(a,typeid(b))
    Is there any way that that won't run typeid if it is already a const type_info & ?

    Possibly using : ?

    That way, the user can either do this:

    is_type(anydata,typeinfodata); // don't run typeid!

    OR

    is_type(anydata,int); // run typeid

    or do I have to have an is_type as well as is_type2 ?
    Last edited by Trauts; 05-16-2003 at 06:07 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Could you overload the is_type2 function for a 2nd parameter of any instead of type_id& ? I dunno if that'll work, just a suggestion

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I could try, but that would be slower.

    Good thinking though!

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Have you looked into dynamic_cast?

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Does it really make that much of a speed difference with just 1 overload? That isn't a rhetorical question, I really don't know the answer to it. Also, if call speed is that big of a concern, any reason why you didn't make that is_type2 function inline?

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Originally posted by ygfperson
    Have you looked into dynamic_cast?
    can you run it on something you pass it?

    I mean I have the functionality I want now... I just need two functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 10:20 PM
  2. Compiling error: Too many arguments.
    By Tuah in forum C++ Programming
    Replies: 16
    Last Post: 06-10-2008, 04:28 PM
  3. Bor to DevC++ prog convert prob
    By kryptkat in forum Windows Programming
    Replies: 16
    Last Post: 09-18-2007, 05:11 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  5. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM