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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:55:09+00:00 2026-06-04T23:55:09+00:00

I am puzzled by std::is_const ‘s behaviour in identifying a const pointer as non-

  • 0

I am puzzled by std::is_const‘s behaviour in identifying a const pointer as non-const.
My own implementation of is_const does exactly the same thing. I’m not sure why the more general templated struct <T>is being picked over the <const T> version. Both gcc4.7 and clang3.1-svn show the same behaviour. Can anyone explain what’s going on? Code is given below:

#include <iostream>
#include <sstream>
#include <type_traits>

class CEmptyClass {}; 

namespace jbc 
{
  template <typename T>
  struct is_const : std::false_type {}; 

  template <typename T>
  struct is_const<const T> : std::true_type {}; 
}

int main(int argc, char* argv[])
{
  std::cout << "Is 'const CEmptyClass*' constant according to std lib : " 
    << std::is_const<const CEmptyClass*>::value << std::endl;
  std::cout << "Is 'const CEmptyClass*' constant according to jbc : " 
    << jbc::is_const<const CEmptyClass*>::value << std::endl;
}

In both instances is_const<const CEmptyClass*>::value returns 0

  • 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-04T23:55:12+00:00Added an answer on June 4, 2026 at 11:55 pm

    There is no such thing as a const reference, a reference is never const. Code like this does not compile:

    int& const i;
    

    Now if you were to remove your reference, it would work. If you were to place const on the right side (semantically is the same thing), and read the type backwards

    CEmptyClass const&
    

    it would read a reference to a const CEmptyClass, not a const reference to an CEmptyClass.

    Update: Now that you changed the reference to a pointer, the same misconstruction persist:

    const CEmptyClass*
    CEmptyClass const*
    

    both are the same, a non-const pointer to a const CEmptyClass

    CEmptyClass* const
    

    is a const pointer to a CEmptyClass

    and

    const CEmptyClass* const
    CEmptyClass const* const
    

    are a const pointer to a const CEmptyClass.

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

Sidebar

Related Questions

I'm just puzzled with this one, it's a Haskell loop-sort-of-thing which I can't figure
I am puzzled - my rootNode has a value, be it dom.html or Document,
I'm a bit puzzled how I'm supposed to use Testflight's SDK jn combination with
I am really puzzled by this. I believe I am managing memory the correct
I'm a bit puzzled: From Cocoa Programming For Mac OS X (page 63, 3rd
I am puzzled. I looked at the trace of a pagecall that was slow
I'm a little puzzled with QueryStrings and ActionResult I have a URL coming in
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I am a bit puzzled with my Regex results (and still trying to get
I am a bit puzzled by this strange behavior on CentOs 5.4 when starting

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.