473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Object introspection

Is there a mechanism in C++ or any library which will give typeinfo
about the members of a struct/class. Something like Boost::type_traits
which will expose type_info of the members too.

Apr 25 '06 #1
4 2326
pr*******@gmail.com wrote:
Is there a mechanism in C++ or any library which will give typeinfo
about the members of a struct/class. Something like Boost::type_traits
which will expose type_info of the members too.


Only if you expose the typeinfo of the members by making the data
members accessible (i.e., public for everyone, protected for
subclasses, or open to friendships) or by publishing one or more member
functions to make it available to the user of the class. Generally
speaking, exposing such information would violate the principle of
encapsulation, which rightly tries to hide implementation details (cf.
http://www.parashift.com/c++-faq-lit....html#faq-7.4).

Cheers! --M

Apr 25 '06 #2
Let me explain furthur, I want to write a smart structure copy template
function which will inspect the argument (struct/class template) and do
a member-wise assignment across the two arguments.

<class T> const T& smart_copy(const T& arg1, T& arg2)

using template metaprogramming (Eg using BOOST_PP* like functions)

Apr 25 '06 #3
pr*******@gmail.com wrote:
Let me explain furthur, I want to write a smart structure copy template
function which will inspect the argument (struct/class template) and do
a member-wise assignment across the two arguments.

<class T> const T& smart_copy(const T& arg1, T& arg2)

using template metaprogramming (Eg using BOOST_PP* like functions)


What's wrong with using T's operator=(), which knows how to do it properly?

e.g.

template<class T>
const T& smart_copy(const T& arg1, T& arg2)
{
return arg2 = arg1;
}

Apr 25 '06 #4
I am trying to use templating to do lot of boilerplate implementations
from an existing codebase (in C) using a c++ compiler (gcc). One way
would be for me to write a correct "=" operation for each struct/class
and use it, but then it is tedious and error-prone (and I am a lazy
person).
Secondly I would like to write generic functions which can introspect
the template parameters and do "stuff" with them. If boost::type_traits
goes so far as to give me some properties of my type, why not give me
the names/types etc of members of that type?
Just curious...

Apr 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Graeme Matthew | last post by:
Hi all, quick one, I hope I am explaining this properly, I am wanting to do some introspection on custom object instances, for example: import md5 >>> m = md5.new() >>> type(m) <type...
11
by: Christopher J. Bottaro | last post by:
I actually want all the parent classes too. So if D derives off C derives off B derives off A, I ultimately want a tuple ('D', 'C', 'B', 'A'). For those of you following the Python Documentation...
4
by: Benjamin Rutt | last post by:
I'm trying to learn about introspection in Python. my ultimate goal is to be able to build a module "text database" of all modules that are in the sys.path, by discovering all candidate modules...
0
by: Steven T. Hatton | last post by:
I suspect the core language is not the level at which introspection should be implemented in C++. That has been the choice of C#, and Java. Both of these languages made some trade-offs to...
4
by: Steven T. Hatton | last post by:
Has there been any substantial progress toward supporting introspection/reflection in C++? I don't intend to mean it should be part of the Standard. It would, nonetheless, be nice to have a...
1
by: James Geurts | last post by:
Hi, Can someone tell me how to test if a field is a const? I am using the FxCop introspection engine, but I suppose I could use reflection if required. for example, the following would return...
6
by: Derek Peschel | last post by:
Here are two functions. def invert_dict_to_lists(dict): lists = {} for key in dict: value = dict if not value in lists: lists = else: lists.append(key)
6
by: Une bévue | last post by:
i'd like to know objects properties and/or methods. saying i do have an object "o" being part of the dom (a div or an ul...) how could i list (introspection) all the properties and methods...
14
by: Dave Rahardja | last post by:
Is there a way to generate a series of statements based on the data members of a structure at compile time? I have a function that reverses the endianness of any data structure: /// Reverse...
8
by: filox | last post by:
is there a way to find out the size of an object in Python? e.g., how could i get the size of a list or a tuple? -- You're never too young to have a Vietnam flashback
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.