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 8821109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:46:21+00:00 2026-06-14T05:46:21+00:00

I need to check if some values are defined in the enum type or

  • 0

I need to check if some values are defined in the enum type or not at runtime in C++. The requirement could be easily accomplished by C# (refer the following code). But C++ doesn’t have type information at runtime (as far as I know). Is there a way to workaround?

PS: In my project, the enum type defines hundreds of values, so I don’t want to duplicate the values in source code (e.g. create a map and push all the valid values into it) that implements the logic which increases the complexity of maintainability.

enum BoFormObjectEnum
{
    fo_Items = 4,
    fo_SalesEmployee = 53,
    fo_TransactionTemplates = 55,
    fo_JournalPosting = 30,
    fo_CheckForPayment = 57,
    fo_PaymentTermsTypes = 40,
    ...
}

class Program
{
    static void Main(string[] args)
    {
        var array = Enumerable.Range(1, 60);
        foreach (var item in array)
        {
            if (Enum.IsDefined(typeof(BoFormObjectEnum), item))
                // do some logic
            else
                // do some other logic
        }
    }
}
  • 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-14T05:46:22+00:00Added an answer on June 14, 2026 at 5:46 am

    C++ does not provide what you want.

    Most “proper” solution is to re-design the whole thing, and not use C++ enum like this. It is not same as C# enum, they are different enough that you should not think of them as a same thing, any more than you think union and enum are same thing. Clear your mind of C# solution, design C++ solution.

    Easiest, especially if enum values do not change often (and if they do, why are they a hard-coded enum?), is to just “bite the bullet” and create a set or a map with valid values, and when you want to know if some number is defined as enum, test if it is in set, or if you also want the name, then use map so you can include both value as int and name as string.

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

Sidebar

Related Questions

I need to check whether a string contains any swear words. Following some advice
If a switch with enum-type argument misses some of the constants and does not
I need to check some settings for all users on Windows clients in the
I need to check if some pictures (eps, tiff files) are in 300 DPI
I need to check in some fast way if there is any text nodes
For some reason I need to check in a couple of files in the
In some of my tests i need to check the order of Lists and
I need to check if a link (a-tag) is the only content (not just
I am new to MySQLdb. I need to read values from a pre-defined database
I am holding some information in static variables defined in page class (not in

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.