Hi
There is an example of the code below (mostly written by P. Bindels).
In that example is strongly highlighted that very important is the
sequence
of compiled code. In C++ could be assume that such a sequence exists.
But the question is if it is a feature or it is a bug?
Especially in the scope of that example we could observe that
templates
can be somehow separated from its specializations .
Best regards.
#include <iostream>
template <class A>
class T {
A a;
};
class is_original_ver sion_of_templat e
{
public:
static bool const value;
};
bool const is_original_ver sion_of_templat e::value
(sizeof(T<void *>) == sizeof(T<void *>));
template <class A>
class T<A *{
A *a[10];
};
class is_not_original _version_of_tem plate // specialized
{
public:
static bool const value;
};
bool const is_not_original _version_of_tem plate::value
(sizeof(T<void *>) == is_original_ver sion_of_templat e::value);
int main()
{
std::cout << "is_original_ve rsion_of_templa te "
<< is_original_ver sion_of_templat e::value << '\n';
std::cout << "is_not_origina l_version_of_te mplate "
<< is_not_original _version_of_tem plate::value << '\n';
}
There is an example of the code below (mostly written by P. Bindels).
In that example is strongly highlighted that very important is the
sequence
of compiled code. In C++ could be assume that such a sequence exists.
But the question is if it is a feature or it is a bug?
Especially in the scope of that example we could observe that
templates
can be somehow separated from its specializations .
Best regards.
#include <iostream>
template <class A>
class T {
A a;
};
class is_original_ver sion_of_templat e
{
public:
static bool const value;
};
bool const is_original_ver sion_of_templat e::value
(sizeof(T<void *>) == sizeof(T<void *>));
template <class A>
class T<A *{
A *a[10];
};
class is_not_original _version_of_tem plate // specialized
{
public:
static bool const value;
};
bool const is_not_original _version_of_tem plate::value
(sizeof(T<void *>) == is_original_ver sion_of_templat e::value);
int main()
{
std::cout << "is_original_ve rsion_of_templa te "
<< is_original_ver sion_of_templat e::value << '\n';
std::cout << "is_not_origina l_version_of_te mplate "
<< is_not_original _version_of_tem plate::value << '\n';
}
Comment