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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:18:31+00:00 2026-06-17T14:18:31+00:00

I have read that C++11 has sufficient static checking (compile time) so as to

  • 0

I have read that C++11 has sufficient static checking (compile time) so as to implement a big part of what should have been Concepts checking of C++11(removed). (I’ve read this in the comments of a recent question about Concepts removed… – that question was fastly closed as not constructive).

The C++03 code below only check the presence of a member function in a class (on which my template class wants to work). Here are 4 member functions that are searched for, and I always use the same pattern:

  • a typedef to define a typedef of the prototype of the function
  • a call to static_cast that breaks compilation if ever the typename TExtension doesn’t define such a member function, or if it has different prototype

Here is the code:

template <typename TExtension>
class
{
...
    void checkTemplateConcept()
    {
        typedef unsigned long (TExtension::*memberfunctionRequestedId)();
        static_cast<memberfunctionRequestedId>(&TExtension::getRequestId);

        typedef eDirection (TExtension::*memberfunctionDirection)();
        static_cast<memberfunctionDirection>(&TExtension::getDirection);

        typedef eDriveWay (TExtension::*memberfunctionDriveWay)();
        static_cast<memberfunctionDriveWay>(&TExtension::getDriveWay);

        typedef unsigned long (TExtension::*memberfunctionCycleId)();
        static_cast<memberfunctionCycleId>(&TExtension::getCycleId);
    }
}

This was in some part of my code, but it was completely based on C++03. I would rewrite it gladly, with those new C++11 features… what should be used here instead ?

  • 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-17T14:18:32+00:00Added an answer on June 17, 2026 at 2:18 pm

    With C++11, you could make the compiler to print the good error messages with static_assert as:

    typedef unsigned long (TExtension::*required_type)();
    typedef decltype(&TExtension::getRequestId) actual_type;
    
    static_assert(std::is_same<required_type, actual_type>::value,
         "The type of getRequestId must be unsigned long (C::*)()");
    

    Now if the type of member function doesn’t match, the compiler will print this helpful message:

    "The type of getRequestId must be unsigned long (C::*)()"
    

    You could make it more descriptive if you want to. 🙂

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

Sidebar

Related Questions

I have a problem that has been nagging me for some time now and
I have read that LinkedHashMap has faster iteration speed than HashMap because its elements
I have a desktop app that has 65 modules, about half of which read
I have read that you should keep the number of connections in your database
I have read that when including a php file that using absolute paths has
I have read that enabling Change Data Capture obviously has an impact on database
I have read that in a case where a table has many columns, but
I have read that nuance has introduced a voice recognition software NINA which is
I have read ( here ) that PyPy has support for CPython extension modules
I have been told that JMeter has some issues with ASP.NET pages, is that

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.