Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:20:17+00:00 2026-06-04T11:20:17+00:00

It looks like calls to boost::any_cast<T>(any&) call some expensive typechecking to make sure that

  • 0

It looks like calls to boost::any_cast<T>(any&) call some expensive typechecking to make sure that the cast is valid. Specifically, it calls performs the following test to make sure the cast is legal:

std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0

If the cast is legal, the code then performs a static_cast.

This seems useful for debug mode, but is rather slow for production code. Is there any way to skip the strcmp?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:20:19+00:00Added an answer on June 4, 2026 at 11:20 am

    boost::any includes a set of undocumented ValueType * unsafe_any_cast(any * operand) functions that do what you want for any* operands.

    You could take the address of your reference to get what you want, or since Boost is open source, you could patch in a set of these function templates to take an any& operand.

    Then just make a wrapper that uses the safe versions in debug builds and the unsafe versions in release builds. However, I’d make at least one further addition – the debug wrappers should catch the exception thrown for an invalid cast and invoke the debugger or crash the program so that when running in debug mode those invalid casts aren’t handled in a way that hides the fact that the release build would have undefined behavior.

    Also keep in mind that Boost reserves the right to remove the unsafe versions:

    // Note: The "unsafe" versions of any_cast are not part of the
    // public interface and may be removed at any time.
    

    So if you decide to use these functions (or patch any.hpp to extend them), you’re buying into some level of maintenance obligation that may or may not be acceptable depending on who your code might be deliverable to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Makefile that looks something like this: sometarget: command_one # calls fork()
I have a call to powershell.exe that looks like this, and which works from
I have code that looks something like this in javascript: forloop { //async call,
If I have a jQuery POST call that looks something like: $.post(url : myserver/1,
I've a simple class that looks like Boost.Array. There are two template parameters T
My application architecture looks like this. GWT in the UI layer -> Calls GWT
It looks like Google's Dart language doesn't allow you to call native js functions
i am using vbscript to call a batch file. my script looks like: dim
When using SqlCommand to call a stored proc via RPC, it looks like it
I have a C++ client app that uses Boost ASIO to make SSL connections

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.