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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:05:04+00:00 2026-06-15T18:05:04+00:00

I want to write a trait-checker named is_pure_func_ptr, which can determine if the type

  • 0

I want to write a trait-checker named is_pure_func_ptr, which can determine if the type is a pure function pointer, as follows:

#include <iostream>

using namespace std;

void f1()
{};

int f2(int)
{};

int f3(int, int)
{};

struct Functor
{
    void operator ()()
    {}
};

int main()
{
    cout << is_pure_func_ptr<decltype(f1)>::value << endl; // output true
    cout << is_pure_func_ptr<decltype(f2)>::value << endl; // output true
    cout << is_pure_func_ptr<decltype(f3)>::value << endl; // output true
    cout << is_pure_func_ptr<Functor>::value << endl;      // output false
    cout << is_pure_func_ptr<char*>::value << endl;        // output false
}

My question is: How to implement it?

  • 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-15T18:05:05+00:00Added an answer on June 15, 2026 at 6:05 pm

    As stated by Joachim Pileborg, std::is_function will do the job.
    If that isn’t an option for you, but you do have C++11 support (meaning you just want to know how to implement it yourself or your standard library isn’t there yet), you could do something like this:

    template<typename T>
    struct is_pure_func_ptr: public std::false_type {};
    template<typename Ret, typename... Args>
    struct is_pure_func_ptr<Ret(Args...)>: public std::true_type {};//detecting functions themselves
    template<typename Ret, typename... Args>
    struct is_pure_func_ptr<Ret(*)(Args...)>: public std::true_type {};//detecting function pointers
    

    This works, but you might need additional work when it comes to supporting functions with different calling conventions and/or cv-qualified pointers

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

Sidebar

Related Questions

I want write a simple query which will fetch data from a table (which
I want write a little code analyzer which parses nested structures and translates into
here is a code which i want to write. int opt; po::options_description desc(Allowed options);
Suppose that I want to write a case class Stepper as follows: case class
Possible Duplicate: Obtaining const_iterator from iterator I want to write a metafunction which returns
I am trying to write a function that can handle both char & wchar_t
Let's assume I want to create a trait that I can mix in into
I'm trying to write a trait (in Scala 2.8) that can be mixed in
I want to finally get to know how to write an application which uses
Hello I want write my own desktop sharing application in Java. The application should

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.