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

The Archive Base Latest Questions

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

C++11 includes a wonderful amount of great features when it comes to type deduction

  • 0

C++11 includes a wonderful amount of great features when it comes to type deduction and management altogether. For example auto and decltype -keywords have proven themselves to be a worthy addition to the language.

As I adopted these simple, yet effective features, I begin to think of implementing some kind of reflection system. Here’s what I’ve managed to pull off this far:

/// ------------------------------------------------------------
/// @class  Reflection
/// @brief  General-purpose reflection class.
/// @exmpl  Get type id:
///             auto a = Reflection::get_id_type<int>();
///             auto b = Reflection::get_id_type<Object>();
///         Get type via received id:
///             decltype(Reflection::get_type(a)) d;
/// @note   It is forbidden to create an instance of this class.
/// ------------------------------------------------------------
class Reflection{
public:
    /// Static member functions:
    template<typename T>
    static inline long get_id_type(void){
        return reinterpret_cast<long>(&Database<T>::id);
    }
    static auto get_type(long const type_id) -> decltype(/* UNFINISHED! */){ // This is where I'm having problems.
        // This function body is intentionally left empty.
        // All that matters is the return type.
    }
private:
    /// Inner structures:
    template<typename T>
    struct Database{
        static void* id; // Created void pointer here, because only the address of this variable matters.
    };
    /// Constructors & destructors:
    Reflection(void) = delete;
    ~Reflection(void) = delete;
    /// Member functions (overloaded operators):
    Reflection& operator=(Reflection&&) = delete;
    Reflection& operator=(Reflection const&) = delete;
};

The code should be easy enough to understand. If you read the overall code with the comments, you should realize how to use this class. But the question is:

“How do I return an expression from function “get_type” in order to
turn this expression into usable type by decltype-specifier?”

Thanks in advance.

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

    You can’t have a return type that depends on the runtime value of an argument. Period. What you’re trying to do is not feasible.

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

Sidebar

Related Questions

I have HTML which includes scripts in following order <script src=../static/js/jquery.js type=text/javascript> <script src=../static/js/bootstrap.js
I need help with includes in PHP. I have a group of files where
Let me explain what I am asking for by an example. Imagine I have
My HTML document includes <font face=helvetica> (and of course </font> later) This works great
I have wsdl that includes many xsds <wsdl:types> <xsd:schema elementFormDefault=qualified targetNamespace=Name/Space> <xsd:include schemaLocation=role.xsd/> <xsd:include
The C++11 standard includes the wonderful std::atomic<T> , which has member functions like this
Hope everyone is enjoying this wonderful Aloha Friday, I have a question about HTML
InstallShield includes the ability to modify an applications .config file via XML File Changes*...
// BOOST Includes #include <boost/assign.hpp> // Boost::Assign #include <boost/assign/list_of.hpp> // Boost::Assign::List_Of #include <boost/assign/std/map.hpp> //
WPF includes the title bar height in the total window height instead of using

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.