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

  • Home
  • SEARCH
  • 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 42321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:19:11+00:00 2026-05-10T15:19:11+00:00

Static metaprogramming (aka template metaprogramming) is a great C++ technique that allows the execution

  • 0

Static metaprogramming (aka ‘template metaprogramming’) is a great C++ technique that allows the execution of programs at compile-time. A light bulb went off in my head as soon as I read this canonical metaprogramming example:

#include <iostream> using namespace std;  template< int n > struct factorial { enum { ret = factorial< n - 1 >::ret * n }; };  template<> struct factorial< 0 > { enum { ret = 1 }; };  int main() {     cout << '7! = ' << factorial< 7 >::ret << endl; // 5040     return 0; } 

If one wants to learn more about C++ static metaprogramming, what are the best sources (books, websites, on-line courseware, whatever)?

  • 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. 2026-05-10T15:19:12+00:00Added an answer on May 10, 2026 at 3:19 pm

    [Answering my own question]

    The best introductions I’ve found so far are chapter 10, ‘Static Metaprogramming in C++’ from Generative Programming, Methods, Tools, and Applications by Krzysztof Czarnecki and Ulrich W. Eisenecker, ISBN-13: 9780201309775; and chapter 17, ‘Metaprograms’ of C++ Templates: The Complete Guide by David Vandevoorder and Nicolai M. Josuttis, ISBN-13: 9780201734843.

    alt text alt text alt text alt text

    Todd Veldhuizen has an excellent tutorial here.

    A good resource for C++ programming in general is Modern C++ Design by Andrei Alexandrescu, ISBN-13: 9780201704310. This book mixes a bit of metaprogramming with other template techniques. For metaprogramming in particular, see sections 2.1 ‘Compile-Time Assertions’, 2.4 ‘Mapping Integral Constants to Types’, 2.6 ‘Type Selection’, 2.7 ‘Detecting Convertibility and Inheritance at Compile Time’, 2.9 ‘NullType and EmptyType‘ and 2.10 ‘Type Traits’.

    The best intermediate/advanced resource I’ve found is C++ Template Metaprogramming by David Abrahams and Aleksey Gurtovoy, ISBN-13: 9780321227256

    If you’d prefer just one book, get C++ Templates: The Complete Guide since it is also the definitive reference for templates in general.

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

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Look for Async Filter Sample in the DirectShow SDK, It… May 11, 2026 at 10:34 am
  • added an answer First question: You are already initializing it with a socket.… May 11, 2026 at 10:34 am
  • added an answer The code I ended up using. I think this is… May 11, 2026 at 10:33 am

Related Questions

Static metaprogramming (aka template metaprogramming) is a great C++ technique that allows the execution
C++ is probably the most popular language for static metaprogramming and Java doesn't support
Static variable gotcha in php I am from Java background and have switched to
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public static IList<T> LoadObjectListAll<T>() { ISession session = CheckForExistingSession(); var cfg = new NHibernate.Cfg.Configuration().Configure();
public static Logger getLogger() { final Throwable t = new Throwable(); final StackTraceElement methodCaller
const static int foo = 42; I saw this in some code here on
public static IQueryable<TResult> ApplySortFilter<T, TResult>(this IQueryable<T> query, string columnName) where T : EntityObject {
A static function retUnique() returns a unique value. My question is that if there
public static List<Vertex<Integer>> petersenGraph() { List<Vertex<Integer>> v = new ArrayList<Vertex<Integer>>(); for (int i =

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.