[cfe-dev] Template error without instantiation?
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Apr 25 11:18:43 PDT 2013
On 25.04.2013, at 09:58, Handa, Ramneek wrote:
> Thanks John.
>
> Making small immaterial adjustments to code:
>
> x--start--x
>
> class A {};
>
> class B {};
>
> void THIS_IS_AN_ERROR(A& myexp) {
> }
>
> template <typename T>
> void mytest(const B &value)
> {
> THIS_IS_AN_ERROR(A(value));
> }
>
> template <typename T>
> void mytest(const T &value)
> {
> //Do something useful, ignore what we had here earlier
> }
>
> x--end--x
>
> It's a case of template specialization where I would like the compiler
> to throw an error if B is being passed to mytest.
> If not I would like it to do the *useful thing*.
Just drop the mytest overload for B and drop this in the generic version:
static_assert(!std::is_same<T, B>::value, "Don't instantiate with B.");
Sebastian
More information about the cfe-dev
mailing list