Re: [eigen] Can we prevent that this compiles? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Hi
Another alternative is having a templated constructor which is a better match
for types other than T:
template<typename T, [...]>
class Replicate
{
[...]
template<typename U> struct dummy;
Replicate(const T& t);
template<typename U> Replicate(const U& u) { dummy<U>::template
ConstructionOnlyPossibleFromType<T>; }
[...]
};
int main()
{
SomeClass obj;
Replicate<SomeOtherClass> r( obj );
}
Here, gcc emits an error like:
: In constructor ‘X<T>::X(const U&) [with U = SomeClass, T = SomeOtherClass]’:
: instantiated from here
: error: ‘ConstructionOnlyPossibleFrom<T>’ is not a member of
‘X<SomeOtherClass>::dummy<SomeClass>’
Does anyone see any problem with either of these approaches?
If not, I guess it's a matter of taste.
Personally, I think the solution posted earlier is cleaner.
Markus
--
PGP key on www.esat.kuleuven.be/~mmoll/public_key.pgp
Fingerprint is
90C4 B47D 1A00 5AC1 9147 3197 EDA7 1E0E 99E4 9EDB