由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
相关主题
The untold truth about C++Bjarne Stroustrup C++第四版电子版出来了
C++,大家觉得最值得买最想买最不后悔买的书是哪本?有人看了新版 1368页的 c++ programming language 吗
VB, C++初学者清推荐书籍C++必备书籍推荐
哪位大侠有如下书籍的电子版,或者下载地址,多谢问个C++的operator conversation function问题
读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。重新捡起C++怎么上手?
(zz)C++11新特性程序語言有兩種。
这么好的帖子没人转?说几个backend从C++导向Java的知名公司吧
有必要开个c++版C++学到什么程度能找到初级工作
相关话题的讨论汇总
话题: reflection话题: template话题: c++话题: macro话题: class
进入Programming版参与讨论
1 (共1页)
e****d
发帖数: 895
1
Isn't it exciting? It's supposed to be finalized in this March.
Not sure when it will be adopted by industries.
t****t
发帖数: 6806
2
还是少了很多重要的东西, 比如reflection和concept.

【在 e****d 的大作中提到】
: Isn't it exciting? It's supposed to be finalized in this March.
: Not sure when it will be adopted by industries.

e****d
发帖数: 895
3
Concept might be in C++1x and reflection never.

【在 t****t 的大作中提到】
: 还是少了很多重要的东西, 比如reflection和concept.
n******t
发帖数: 4406
4
这些东西,真的有那么有用么?

【在 t****t 的大作中提到】
: 还是少了很多重要的东西, 比如reflection和concept.
t****t
发帖数: 6806
5
concept我觉得没有也过得去, reflection还是很有用的.
关键是, 看上去0x的方向是更高层次的抽象(比如说对variadic template的支持). 但
是reflection没有的话, 这个抽象就少了一块.

【在 n******t 的大作中提到】
: 这些东西,真的有那么有用么?
e****d
发帖数: 895
6
Do you think reflection can be mostly implemented
using template?

【在 t****t 的大作中提到】
: concept我觉得没有也过得去, reflection还是很有用的.
: 关键是, 看上去0x的方向是更高层次的抽象(比如说对variadic template的支持). 但
: 是reflection没有的话, 这个抽象就少了一块.

D*******a
发帖数: 3688
7
不是一个概念

【在 e****d 的大作中提到】
: Do you think reflection can be mostly implemented
: using template?

e****d
发帖数: 895
8
I know they are not the same thing such as one
for compile time while the other for runtime.
But can I use template to achieve the same or
similar effect of reflection.

【在 D*******a 的大作中提到】
: 不是一个概念
t****t
发帖数: 6806
9
you use RTTI to achieve reflection-like effect. template has nothing to do
with it. C++ RTTI is very limited, and if you want to use that for
reflection it's going to be awkward. macro is probably better.

【在 e****d 的大作中提到】
: I know they are not the same thing such as one
: for compile time while the other for runtime.
: But can I use template to achieve the same or
: similar effect of reflection.

e****d
发帖数: 895
10
Template definitely can implement something similar to
reflection.
For each class that you want reflection enabled, use
template to define a meta class for it.

【在 t****t 的大作中提到】
: you use RTTI to achieve reflection-like effect. template has nothing to do
: with it. C++ RTTI is very limited, and if you want to use that for
: reflection it's going to be awkward. macro is probably better.

相关主题
(zz)C++11新特性Bjarne Stroustrup C++第四版电子版出来了
这么好的帖子没人转?有人看了新版 1368页的 c++ programming language 吗
有必要开个c++版C++必备书籍推荐
进入Programming版参与讨论
t****t
发帖数: 6806
11
for one thing, how do you plan to get the name of the class, or the name of
the member, with template?

【在 e****d 的大作中提到】
: Template definitely can implement something similar to
: reflection.
: For each class that you want reflection enabled, use
: template to define a meta class for it.

e****d
发帖数: 895
12
Manually fill in the class name in the meta class.

of

【在 t****t 的大作中提到】
: for one thing, how do you plan to get the name of the class, or the name of
: the member, with template?

t****t
发帖数: 6806
13
lol manually, then why do we need reflection...

【在 e****d 的大作中提到】
: Manually fill in the class name in the meta class.
:
: of

e****d
发帖数: 895
14
take a look at the struct adapter in boost::fusion.

【在 t****t 的大作中提到】
: lol manually, then why do we need reflection...
t****t
发帖数: 6806
15
yeah, it used macro.

【在 e****d 的大作中提到】
: take a look at the struct adapter in boost::fusion.
s******n
发帖数: 876
16
If there is such a macro system that's universally accepted
and all libs can reliably depend on it, it is effectively
a radical change to language itself. Achieving such a macro
system is no less difficult than having reflection built in.

【在 e****d 的大作中提到】
: Do you think reflection can be mostly implemented
: using template?

X****r
发帖数: 3557
17
Macro and reflection are different things. Macro is compiling
time and reflection is runtime.

【在 s******n 的大作中提到】
: If there is such a macro system that's universally accepted
: and all libs can reliably depend on it, it is effectively
: a radical change to language itself. Achieving such a macro
: system is no less difficult than having reflection built in.

e****d
发帖数: 895
18
Right, it uses macro. But it's built on top of templates.
boost::mpl also uses macro a lot. But it's a classical
example of template meta-programming.

【在 t****t 的大作中提到】
: yeah, it used macro.
e****d
发帖数: 895
19
No, not macro. C++ template is quite complicated and
it's turing complete. Should be doable to implement
something similar to reflection by using template.

【在 s******n 的大作中提到】
: If there is such a macro system that's universally accepted
: and all libs can reliably depend on it, it is effectively
: a radical change to language itself. Achieving such a macro
: system is no less difficult than having reflection built in.

s******n
发帖数: 876
20
Some C++ people, when confronted with a problem, think
“I know, I'll use template.”Now they have N+1 problems.
Kidding aside, if you did it, you effectively
created a new language. The question is whether
other people speak the same language too.

【在 e****d 的大作中提到】
: No, not macro. C++ template is quite complicated and
: it's turing complete. Should be doable to implement
: something similar to reflection by using template.

相关主题
问个C++的operator conversation function问题说几个backend从C++导向Java的知名公司吧
重新捡起C++怎么上手?C++学到什么程度能找到初级工作
程序語言有兩種。c++ cast problem
进入Programming版参与讨论
d****p
发帖数: 685
21
Interesting ... how turing completeness at compile time is related to
reflection at runtime?

【在 e****d 的大作中提到】
: No, not macro. C++ template is quite complicated and
: it's turing complete. Should be doable to implement
: something similar to reflection by using template.

e****d
发帖数: 895
22
I didn't mention runtime.
What I mean it's to do something similar to reflection
at compile time using template.

【在 d****p 的大作中提到】
: Interesting ... how turing completeness at compile time is related to
: reflection at runtime?

e****d
发帖数: 895
23
This is the fun of C++. :-D

【在 s******n 的大作中提到】
: Some C++ people, when confronted with a problem, think
: “I know, I'll use template.”Now they have N+1 problems.
: Kidding aside, if you did it, you effectively
: created a new language. The question is whether
: other people speak the same language too.

t****t
发帖数: 6806
24
no, not complete yet. when you have no access to name of member/class/object
, essentially you have no way to do reflection. the missing piece is the #
name operator in preprocessor; if you don't have it, you have a big missing
chain in the machine. so as you see, every "reflection simulator" library
use macro here or there.
i don't mean macro is reflection. but in current standard, the #name
operator is almost the only way to implement reflection-like mechanism in a
library. as for template, of course template is an important thing here, but
it's not more important than other chains in the machine. the missing piece
is always the most important, if you know what i mean (the shortest board
decides the maximum capacity).
that said, if the committee decides to add reflection, i am sure they have
better way (e.g. better/complete RTTI support, as opposed to current vague
"implementation-defined" RTTI)

【在 e****d 的大作中提到】
: No, not macro. C++ template is quite complicated and
: it's turing complete. Should be doable to implement
: something similar to reflection by using template.

g*****g
发帖数: 34805
25
Interesting, assembly is also tuning complete,
and essentially it can do anything.

【在 e****d 的大作中提到】
: I didn't mention runtime.
: What I mean it's to do something similar to reflection
: at compile time using template.

e****d
发帖数: 895
26
Well, you cannot compare assembly with the others.
Assembly is powerful, but not scalable.
When I mentioned template is turing complete, I mean
theoretically template can implement reflection.
Some of them are quite straightforward such as checking
whether a class has a member type, a member function or
iterating its public data members. Of course, it will be
difficult to implement a complete set of reflection
functionalities.

【在 g*****g 的大作中提到】
: Interesting, assembly is also tuning complete,
: and essentially it can do anything.

e****d
发帖数: 895
27
Life will be much easier if the language itself supports reflection.
But before that, if we want to do something reflection-like in
C++, template is the way to go. And definitely pre-processing
will be used since it's a fundamental way to deal with tokens.

object
missing
a
but
piece

【在 t****t 的大作中提到】
: no, not complete yet. when you have no access to name of member/class/object
: , essentially you have no way to do reflection. the missing piece is the #
: name operator in preprocessor; if you don't have it, you have a big missing
: chain in the machine. so as you see, every "reflection simulator" library
: use macro here or there.
: i don't mean macro is reflection. but in current standard, the #name
: operator is almost the only way to implement reflection-like mechanism in a
: library. as for template, of course template is an important thing here, but
: it's not more important than other chains in the machine. the missing piece
: is always the most important, if you know what i mean (the shortest board

D*******a
发帖数: 3688
28
anything is too cumbersome to use it is useless.
you can use C++ to write JVM then by definition you have reflection!
you can use function pointers and structs, who needs C++?

【在 e****d 的大作中提到】
: Well, you cannot compare assembly with the others.
: Assembly is powerful, but not scalable.
: When I mentioned template is turing complete, I mean
: theoretically template can implement reflection.
: Some of them are quite straightforward such as checking
: whether a class has a member type, a member function or
: iterating its public data members. Of course, it will be
: difficult to implement a complete set of reflection
: functionalities.

e****d
发帖数: 895
29
You can ask Bjarne Stroustrup about who needs C++.

【在 D*******a 的大作中提到】
: anything is too cumbersome to use it is useless.
: you can use C++ to write JVM then by definition you have reflection!
: you can use function pointers and structs, who needs C++?

D*******a
发帖数: 3688
30
you totally missed the point.
we use language constructs for convenience, to facilitate implementation. C
has function pointers so it can be used to do what C++ can do (polymorphism,
inheritance, etc). However, it is just very cumbersome and error prone. C++
has these functionalities built in so people can use them easily.
As for reflection, you maybe smart enough to do it using template, but will
that be as easy as Class.forName("...")? If programmer needs to jump through
a lot of hoops, rewriting their old classes to do this, it is useless.

【在 e****d 的大作中提到】
: You can ask Bjarne Stroustrup about who needs C++.
相关主题
见过的几个大牛C++,大家觉得最值得买最想买最不后悔买的书是哪本?
王垠继续喷各路大神:我为什么在乎这一个A+ (转载)VB, C++初学者清推荐书籍
The untold truth about C++哪位大侠有如下书籍的电子版,或者下载地址,多谢
进入Programming版参与讨论
X****r
发帖数: 3557
31
The more I think about it, the more I feel that C++ template
system is heading to the wrong direction.
If they had transformed pre-processing into a real embedded
language with APIs to compile-time objects, you can do all
template can do with the same minimal run-time cost. And it
will be much much easier to use and extend.

implementation. C
(polymorphism,
prone. C++
will
through
useless.

【在 D*******a 的大作中提到】
: you totally missed the point.
: we use language constructs for convenience, to facilitate implementation. C
: has function pointers so it can be used to do what C++ can do (polymorphism,
: inheritance, etc). However, it is just very cumbersome and error prone. C++
: has these functionalities built in so people can use them easily.
: As for reflection, you maybe smart enough to do it using template, but will
: that be as easy as Class.forName("...")? If programmer needs to jump through
: a lot of hoops, rewriting their old classes to do this, it is useless.

e****d
发帖数: 895
32
I think we are talking about different things. My point is
you can still implement reflection-like logic using template + macro
since c++ doesn't have built-in Reflection.
Your point is that something is useless if it's cumbersome, which
I don't disagree on.

C
polymorphism,
++
will
through

【在 D*******a 的大作中提到】
: you totally missed the point.
: we use language constructs for convenience, to facilitate implementation. C
: has function pointers so it can be used to do what C++ can do (polymorphism,
: inheritance, etc). However, it is just very cumbersome and error prone. C++
: has these functionalities built in so people can use them easily.
: As for reflection, you maybe smart enough to do it using template, but will
: that be as easy as Class.forName("...")? If programmer needs to jump through
: a lot of hoops, rewriting their old classes to do this, it is useless.

e****d
发帖数: 895
33
C++0x doesn't bring too much to template except variadic
template and template alias.
Preprocessing is about token scanning and processing, which
is before the compilation stage. It might not be practical
to put in any PP api in it.

【在 X****r 的大作中提到】
: The more I think about it, the more I feel that C++ template
: system is heading to the wrong direction.
: If they had transformed pre-processing into a real embedded
: language with APIs to compile-time objects, you can do all
: template can do with the same minimal run-time cost. And it
: will be much much easier to use and extend.
:
: implementation. C
: (polymorphism,
: prone. C++

t****t
发帖数: 6806
34
of course you can. i actually wrote a framework in my work so i am quite
familiar with it. my colleagues use it and are happy with it, however they
are not programmers.
for me, an amateur programmer, the more i look at it i feel more stupid it
is---macros are typeless and syntaxless, which is against the spirit of c++.
it's not totally useless since our group use it everyday. but it is stupid.
that's why i wish they have reflection in c++0x-- but no.
of course it is built on template. but as i said, as a chain in the big
picture, it's not more important than anything else -- for example, it's not
more important than class, or string, or pointer-to-member. but macro is
stupid.

【在 e****d 的大作中提到】
: I think we are talking about different things. My point is
: you can still implement reflection-like logic using template + macro
: since c++ doesn't have built-in Reflection.
: Your point is that something is useless if it's cumbersome, which
: I don't disagree on.
:
: C
: polymorphism,
: ++
: will

X****r
发帖数: 3557
35
Yes, that's why I said transform. Well maybe I shouldn't have
mentioned prerpocessing at all, because what I have imagined
is totally different. e.g.
instead of
template
class vector {
...
};
template<>
class vector {
...
};
We could have (using % as a special symbol)
%function vectorOf(%type T) {
%var Name = "vectorOf" + T.name();
%if (T == %BuiltInTypes.boolean) {
%return class $Name {
...
};
} %else {
%return class $Name {
...
};
}
}
Not only this would make reflection-like compile-time
constructs trivial, it also gives lot more freedoms.
Say the two generated classes only differ in one line,
we can make an %if on that line only.
And no more SFINAE! Those might be good brain teasers,
but there is really no point to use such convoluted way
to retrieve what the compiler already knows. The error
message would be much more sane, too.

【在 e****d 的大作中提到】
: C++0x doesn't bring too much to template except variadic
: template and template alias.
: Preprocessing is about token scanning and processing, which
: is before the compilation stage. It might not be practical
: to put in any PP api in it.

t****t
发帖数: 6806
36
actually there is no need to make it so dramatic -- just make SFINAE
everywhere (read: easy to use) and hidden. basically you need something like
%if-%else (compile-time if) and compile conditionally according to that,
while ignoring dead forks; and some additional operator/builtin function
like typeof(), nameof() (class name, member name, etc), and a variant type (
something better than void*, such as boost::any) with proper exception.

【在 X****r 的大作中提到】
: Yes, that's why I said transform. Well maybe I shouldn't have
: mentioned prerpocessing at all, because what I have imagined
: is totally different. e.g.
: instead of
: template
: class vector {
: ...
: };
: template<>
: class vector {

d****p
发帖数: 685
37
Hmm, you are proposing generic compiler API and this is way too ambitious...
boost type_traits is_same does the same. but it is based on temp
specialization.

【在 X****r 的大作中提到】
: Yes, that's why I said transform. Well maybe I shouldn't have
: mentioned prerpocessing at all, because what I have imagined
: is totally different. e.g.
: instead of
: template
: class vector {
: ...
: };
: template<>
: class vector {

e****d
发帖数: 895
38
Except nameof(), there are equivalent items for the ones you
suggested. Any obvious advantage to add them?
%if-%else => template partial/explicit specialization + SFINAE
typeof() => template partial/explicit specialization + auto
+ decltype + suffix function return syntax
variant type => boost::any, template type parameter.
It seems to me those items you suggested are cosmetic.

like
(

【在 t****t 的大作中提到】
: actually there is no need to make it so dramatic -- just make SFINAE
: everywhere (read: easy to use) and hidden. basically you need something like
: %if-%else (compile-time if) and compile conditionally according to that,
: while ignoring dead forks; and some additional operator/builtin function
: like typeof(), nameof() (class name, member name, etc), and a variant type (
: something better than void*, such as boost::any) with proper exception.

e****d
发帖数: 895
39
It seems to be another compilation layer for metaprogramming.

【在 X****r 的大作中提到】
: Yes, that's why I said transform. Well maybe I shouldn't have
: mentioned prerpocessing at all, because what I have imagined
: is totally different. e.g.
: instead of
: template
: class vector {
: ...
: };
: template<>
: class vector {

t****t
发帖数: 6806
40
i am referring to xentar's post. of course these are cosmetic, the whole
template is cosmetic version of macro.

【在 e****d 的大作中提到】
: Except nameof(), there are equivalent items for the ones you
: suggested. Any obvious advantage to add them?
: %if-%else => template partial/explicit specialization + SFINAE
: typeof() => template partial/explicit specialization + auto
: + decltype + suffix function return syntax
: variant type => boost::any, template type parameter.
: It seems to me those items you suggested are cosmetic.
:
: like
: (

相关主题
哪位大侠有如下书籍的电子版,或者下载地址,多谢这么好的帖子没人转?
读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。有必要开个c++版
(zz)C++11新特性Bjarne Stroustrup C++第四版电子版出来了
进入Programming版参与讨论
e****d
发帖数: 895
41
It's interesting to know "the whole template is
cosmetic version of macro".

【在 t****t 的大作中提到】
: i am referring to xentar's post. of course these are cosmetic, the whole
: template is cosmetic version of macro.

t****t
发帖数: 6806
42
is it not? basically a big macro with semantics. specialization is cosmetic
version of #if.
of course you get compiler support such as parameter check, and repetitive
defintion don't get error, but essentially it's just macro.

【在 e****d 的大作中提到】
: It's interesting to know "the whole template is
: cosmetic version of macro".

e****d
发帖数: 895
43
My understanding of "cosmetic" change is that the change is minor.
Will you give an example to find out whether a class
has a public member function ro not by using macro instead of template?

cosmetic

【在 t****t 的大作中提到】
: is it not? basically a big macro with semantics. specialization is cosmetic
: version of #if.
: of course you get compiler support such as parameter check, and repetitive
: defintion don't get error, but essentially it's just macro.

1 (共1页)
进入Programming版参与讨论
相关主题
C++学到什么程度能找到初级工作读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。
c++ cast problem(zz)C++11新特性
见过的几个大牛这么好的帖子没人转?
王垠继续喷各路大神:我为什么在乎这一个A+ (转载)有必要开个c++版
The untold truth about C++Bjarne Stroustrup C++第四版电子版出来了
C++,大家觉得最值得买最想买最不后悔买的书是哪本?有人看了新版 1368页的 c++ programming language 吗
VB, C++初学者清推荐书籍C++必备书籍推荐
哪位大侠有如下书籍的电子版,或者下载地址,多谢问个C++的operator conversation function问题
相关话题的讨论汇总
话题: reflection话题: template话题: c++话题: macro话题: class