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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:32:14+00:00 2026-06-13T03:32:14+00:00

How to calculate some mathematical expression i.e. finding factorial of n; during compiletime in

  • 0

How to calculate some mathematical expression i.e. finding factorial of n; during compiletime in c++ ?

  • 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-13T03:32:15+00:00Added an answer on June 13, 2026 at 3:32 am

    Here is a wiki article about template meta-programing in C++.

    Here is another wiki article about compile-time function execution.

    Here is a SO question regarding the factorial.

    Let’s take the wiki xample of computing factorial in compile-time.

    template <int N>
    struct Factorial {
        enum { value = N * Factorial<N - 1>::value };
    };
    
    template <>
    struct Factorial<0> {
        enum { value = 1 };
    };
    
    // Factorial<4>::value == 24
    // Factorial<0>::value == 1
    const int x = Factorial<4>::value; // == 24
    const int y = Factorial<0>::value; // == 1
    

    Since all of the arguments needed are known in the compile time (they are explicitly mentioned in Factorial<4>, for example), the compiler is able to generate all the needed code. After that, the value of the Factorial<4> struct will be 24 which can be later used as if you’ve hardcoded it yourself.

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

Sidebar

Related Questions

I'd like to calculate some simple statistics (percentages) from a table in mysql. The
class A(models.Model): def calculate(self): # calculate some field based on all self.b_set instances class
I am trying to conditionally calculate some values based on user inputs in a
I've got two Activities. In one I calculate some things and therefore I have
I'm trying to use the RQuantLib package to calculate greeks for some options but
I have some jquery which will calculate the items in my menu and assign
Can anyone suggest some fast ways to calculate the lowest common factor(excluding 1) of
How can i calculate the size of only some rows for each table? For
Possible Duplicate: Calculate age in JavaScript In some point of my JS code I
I need to calculate the within and between run variances from some data as

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.