|
-
Oct 29th, 2001, 09:02 AM
#1
Thread Starter
transcendental analytic
objects as template parameters
PHP Code:
struct asdf{int z;};
template <asdf* y>
class c{static const int l;};
template <asdf* y>
const int c<y>::l=y->z;
I wonder how the compiler deals with this? It sure compiles but the templatized class c has to instantiate at compile time, how on earth is it suppose to dereference the asdf pointer
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 29th, 2001, 11:18 AM
#2
did you try to use this construct? I mean, which address do you supply as template parameter? It must be a constant (like 0xa00000), am I right?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 29th, 2001, 02:12 PM
#3
Thread Starter
transcendental analytic
PHP Code:
struct asdf{int z;asdf(int pz):z(pz){};} x(4);
template <asdf* y>
struct c{static const int l;};
template <asdf* y>
const int c<y>::l=y->z;
int main(){
cout << c<&x>::l << endl;
x.z=5;
cout << c<&x>::l << endl;
return 0;
};
It seems like it's done at compile time, at least changing it at runtime won't affect the datatype. I am truly amazed by this 
BTW can anyone check it out with assembler listings? I don't want to rely that it executes a contructor and why not a whole bunch of functions at compile time if it actually doesnt
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 29th, 2001, 02:30 PM
#4
My best guess:
the address of a variable is known at compile time. Therefor it can be used to create a real struct out of your template. The created code looks like this:
Code:
struct asdf{
int z;
asdf(int pz)
:z(pz)
{};
} x(4);
struct _@3479AD32h_@c { // or whatever temporary name where the template parameter is coded inside
static const int l;
};
// this is copied here, so it doesn't need to change later
const int _@3479AD32h_@c::y = (asdf*)(0x3479AD32)->z;
int main(){
cout << _@3479AD32h_@c::l << endl;
x.z=5; // this has no effect because _@3479AD32h_@c::l is a copy of x.z, not a reference
cout << _@3479AD32h_@c::l << endl;
return 0;
};
(&x = 0x3479AD32)
Is my assumption true?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 29th, 2001, 03:05 PM
#5
Thread Starter
transcendental analytic
Okay That gives new life in partial evaluation with templates which didn't work too well in MSVC
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|