Thread: C++ needs reflection support

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    C++ needs reflection support

    Are there any plans to add reflection support in the new standard? If there is one area where C++ is lacking it is in the area of reflection. With managed C++ or C++/CLI you can create some pretty generic module loaders via reflection without being forced to use a parameterized factory to factory out the objects. I know there are workarounds and design patterns such as the factory and/or abstract factory pattern but they are still not generic enough b/c you cannot new up a type that is passed in. You can create conditionals on a string, switch on an ID, etc., to create the object and/or a new factory to factory the object but reflection is non-existent. There are some API's available that mimic reflection for C++ and it can sort of be done in some nasty template meta-programming but I am of the opinion the language desperately needs direct support for reflection.

    Reflection also enables code to 'look at' an object and find its members, properties, etc. Having used the property grid control to browse objects in various tools this type of support is extremely valuable and makes the code very simple. It also allows a tool to generically invoke a function via its name as well as provide facilities to pass in parameters of the correct type. Without this a generic invoke has to be written that, while possible, is not as elegant as a reflection solution.

    I heard that way back when Bjarne was looking into eXtended Type Information or XTI. Has this been tabled or was it added?

    What are your thoughts?
    Last edited by VirtualAce; 10-15-2011 at 10:12 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is no reflect support in the current standard (C++11) from what I know, nor are there any plans to add it.
    But as for the future, I cannot say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Indeed. It does not seem to be an emergent issue.

    I think the biggest argument against the inclusion of Reflection in C++ has to be the conservative "You don't pay for what you don't use" approach to C++. So I can only see this feature being added as a non standard library. Boost::TypeTraits being probably your current best bet.

    That said, I'll take a risk here and suggest we start shipping with debugging symbols. There are genuine reasons not to do it. And I can accept those. But generally speaking with the years these have been becoming fewer and fewer. Even for most commercial software. And if we have some manner of control over the installation environment even better. Of course, this will not deal with those type of applications where it isn't practical to ship and install debugging information. But I sustain those applications aren't so common as they used to be. The main argument here is storage media, which has basically overtaken most of our distribution and storage needs.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Searching open-std.org for "reflection" brings up a few documents that discuss reflection in C++, such as N1471, N1751 and N1775. However, none of these form a concrete, viable proposal, so nothing was added to the language. If you want such a thing, the best way would be to come up with a coherent way of extending the language, then create a proof-of-concept implementation by modifying an existing compiler such as GCC or Clang.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    I wouldn't want reflection in C++. Adding the the extra type overhead would kill a lot of the advantages it has over languages like Java and C#. And for the amount of times I could imagine using such a feature it would be a real killer.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Any successful reflection mechanism in C++ would, in my opinion, be exposed at compile time, with a library (hopefully a standard library) provided to explicitly promote the information to runtime for exactly those types you ask for. That would keep with the philosophy of C++.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CAMP - new open-source reflection library for C++
    By Laurent Gomila in forum Projects and Job Recruitment
    Replies: 23
    Last Post: 11-21-2010, 10:50 PM
  2. iterate through types in a library (reflection)
    By bling in forum C++ Programming
    Replies: 1
    Last Post: 10-29-2008, 05:15 PM
  3. Two basic questions about reflection
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 08:52 PM
  4. Reflection?
    By Neighbor Moby in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2004, 10:04 AM
  5. does IIS support PHP?
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-24-2002, 03:37 PM